
如图,我用注解自动装配不了,报空指针异常,debug 值为 NULL 现在我只能用构造函数来手动装配曲线救国,这是什么问题导致的自动装配失败的?
可能是哪里出的问题?

如图,我用注解自动装配不了,报空指针异常,debug 值为 NULL 现在我只能用构造函数来手动装配曲线救国,这是什么问题导致的自动装配失败的?
可能是哪里出的问题?
|
LaudOakMay 15, 2017 via Android
1
姿势不对吧,Bean 那边怎么定义的
|
|
2
@LaudOak
``` @Service("ItemIndexService") public class ItemIndexServiceImpl implements ItemIndexService { @Autowired private ItemIndexMapper itemindexmapper; @Transactional public ItemIndex selectById(int id) { return itemindexmapper.selectById(id); } @Transactional public List<ItemIndex> findAll() { List<ItemIndex> findAll = itemindexmapper.findAll(); return findAll; } @Transactional public int deleteItemIndex(int id) { return itemindexmapper.deleteItemIndex(id); } @Transactional public int insertItemIndex(ItemIndex itemindex) { return itemindexmapper.insertItemIndex(itemindex); } @Transactional public int updateItemIndex(ItemIndex itemindex) { return itemindexmapper.updateItemIndex(itemindex); } } ``` |
|
4
@acrisliu
``` public class ExcelDataPackage { @Autowired @Qualifier("ItemIndexService") private ItemIndexService itemIndexService; @Autowired @Qualifier("ItemDetailService") private ItemDetailService itemDetailService; private List<ItemIndex> itemIndices; public int findIndexCache(ItemIndex index){ } public void bindObject(){ } public void insertObject(){ } } ``` 我没有加 @Component 注解,我这里只要装配就好了,本身不需要作为一个组件来使用,不用加 @Component 的吧? 而且我加了也依旧装不上 |
|
stackboomMay 15, 2017
5
这个类 你 new 出来的吧 。 |
|
6
@stackboom
卧槽...是的....我为了方便在 test 里面直接 psvm 里面 new 了,应该是要在 @Controller 或者别的 Compant 下面让 Spring 再把我这个类本身也装配进来是吧》。。。。 |
|
7
@mikicomo #6 test 使用 spring test+ junit 也可以注入, 如果你是 psvm 从 spring 容器取吧。这样 spring
才会帮你注入。 |