eclipse&myeclipse 生成jar包后,spring无法扫描到bean定义

时间:2021-05-01 22:47:07

问题:eclipse&myeclipse 生成jar包后,spring无法扫描到bean定义

在使用getbean或者扫包时注入bean失败,但在IDE里是可以正常运行的?

原因:导出jar未将目录一起导出。

解决方法:将代码目录一起导出:一定要勾选 Add directory enttries

eclipse&myeclipse 生成jar包后,spring无法扫描到bean定义

区别:

代码结构:

eclipse&myeclipse 生成jar包后,spring无法扫描到bean定义

未勾选,导出内容为:

META-INF/MANIFEST.MF
com/wang/util/DateStyle.class
com/wang/util/PropertiesUtil$1.class
com/wang/util/PropertiesUtil.class
com/wang/util/Week.class
com/wang/util/DateUtil.class
com/wang/vo/request/hotel/test/PopularCityRequest.class
com/wang/vo/request/hotel/test/EconomicsRequest.class
com/wang/vo/request/hotel/test/HotelProductVouchRequest.class
com/wang/vo/request/hotel/test/QueryOrderListRequest.class
com/wang/vo/request/hotel/test/HotelListQueryRequest.class
com/wang/vo/request/hotel/test/RoomReserveRequest.class
com/wang/vo/request/hotel/test/HotelOneQueryRequest.class
com/wang/vo/request/hotel/test/HotelBrandRequest.class

勾选,导出内容为:

META-INF/MANIFEST.MF
com/
com/wang/
com/wang/util/
com/wang/util/DateStyle.class
com/wang/util/PropertiesUtil$1.class
com/wang/util/PropertiesUtil.class
com/wang/util/Week.class
com/wang/util/DateUtil.class
com/wang/vo/
com/wang/vo/request/
com/wang/vo/request/hotel/
com/wang/vo/request/hotel/test/
com/wang/vo/request/hotel/test/PopularCityRequest.class
com/wang/vo/request/hotel/test/EconomicsRequest.class
com/wang/vo/request/hotel/test/HotelProductVouchRequest.class
com/wang/vo/request/hotel/test/QueryOrderListRequest.class
com/wang/vo/request/hotel/test/HotelListQueryRequest.class
com/wang/vo/request/hotel/test/RoomReserveRequest.class
com/wang/vo/request/hotel/test/HotelOneQueryRequest.class
com/wang/vo/request/hotel/test/HotelBrandRequest.class