spring boot mybatis 打成可執行jar包後啟動UnsatisfiedDependencyException異常
阿新 • • 發佈:2018-12-30
我的spring boot + mybatis專案在idea裡面執行正常,但釋出測試環境打成可執行jar包後就啟動失敗,提示錯誤如下:
[ ERROR] [2018-08-30 17:23:48] org.springframework.boot.SpringApplication [845] - Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookingController': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookingService': Unsatisfied dependency expressed through field 'mapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'citiesMapper' defined in URL [jar:file:/D:/Code/YSL_TravelSupport_CodeSource
/trunk/src/YSL_TS_Java/start-bat/ysl-ts-core-service-hotel-1.0-SNAPSHOT.jar!/BOOT-INF/classes!/com/ysl/ts/core/service/hotel/mapper/ts_hotel/CitiesMapper.class]: Unsatisfied dependency expressed
through bean property 'sqlSessionFactory'; nested exceptionis org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource
[com/ysl/ts/core/service/hotel/config/HotelMybatisPlusConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'class path resource [mapper/ts_hotel_order/HotelRefundMoneyTaskMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'class path resource [mapper/ts_hotel_order/HotelRefundMoneyTaskMapper.xml]'.
Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'HotelOrdersModel'.
Cause: java.lang.ClassNotFoundException: Cannot find class: HotelOrdersModel
最後有一句寫著:Cannot find class: HotelOrdersModel 找不到HotelOrdersModel類,開啟這個mapper xml看到這裡類在一個sql的resultType屬性中使用
<select id="find" resultType="HotelOrdersModel">
這裡不應該只寫類名,而應該寫全完整類名,就是包含包名的類名
<select id="find" resultType="com.ysl.ts.core.model.hotel.ts_hotel_order.HotelOrdersModel">
這樣修改完成後再打包釋出執行就解決了。