Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

Spring @Autowired not working , bean is null

I am using spring 5.2.8

I am using @Autowired to get create the Bean. But i am getting NullPointer when I used this bean

configuration

@Configuration
@Primary
@ComponentScan(basePackages = {"com.try.appli"})
@EnableJpaRepositories(basePackages = "com.tryappli.persistence")
@EnableTransactionManagement
public class AppliConfiguration {

...

My component in package com.try.appli

@Component
@Primary
public class Mycomponent extends MycomponentAbstract {


    @Autowired
    MyService service 

     public handle()
        String data ="{data to update}";
        service.update(data);

service :

@Service
public MyService {

    @Autowired
    private RestOperations resoperation;

    public void update(dataToUpdate) {
        restOperations.put("url", dataToUpdate);
    }
....

I also tried to put the annotation on the implementation but without success

In web.xml

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
question from:https://stackoverflow.com/questions/65848687/spring-autowired-not-working-bean-is-null

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...