spring@autowired不工作,bean为空

q0qdq0h2  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(229)

我使用的是Spring5.2.8
我正在使用@autowired来创建bean。但是当我用这个豆子的时候,我得到了空指针
配置

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

...

包com.try.appli中的我的组件

@Component
@Primary
public class Mycomponent extends MycomponentAbstract {

    @Autowired
    MyService service 

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

服务:

@Service
public MyService {

    @Autowired
    private RestOperations resoperation;

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

我还尝试在实现上添加注解,但没有成功
在web.xml中

<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题