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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…