漠北空城 2016-10-23 10:00 采纳率: 0%
浏览 13907

Spring boot打成jar包,依赖的config及lib文件外置,项目无法启动

最终想达到的效果:
将项目打成jar包,并且依赖的其他jar包以及配置文件外置
问题描述:
在开发工具中,运行项目正常启动,打成jar包之后运行产生bean无法注入的错误,详细见infromation.log。
其中:加上spring-boot-maven-plugin插件打成jar包,运行没有问题,不过却包含了两份依赖的jar包,内外各一份。对应的dao也加上了@Repository注解

 Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.hhly.information.dao.InformationMapper com.hhly.information.sevice.impl.InformationServiceImpl.informationDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.hhly.information.dao.InformationMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    ... 43 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.hhly.information.dao.InformationMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    ... 45 common frames omitted

环境:
Spring boot版本:1.3.5.RELEASE
Java 版本:1.7
开发工具:Eclipse neon

pom.xml配置:

 <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <!--
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <maimClass>com.hhly.information.InformationApplication</maimClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
             -->
            <plugin> 
                <groupId>org.apache.maven.plugins</groupId> 
                <artifactId>maven-jar-plugin</artifactId> 
                <configuration> 
                    <archive> 
                    <!-- 添加index则不从mainfest中读取classpath,而是从Index.list中读取 --> 
                    <!--  <index>true</index> --> 
                        <manifest> 
                            <mainClass>com.hhly.information.InformationApplication</mainClass> 
                            <!-- to create a class path to your dependecies you have to fill true in this field --> 
                            <addClasspath>true</addClasspath> 
                            <classpathPrefix>lib/</classpathPrefix> 
                            <!--<classpathLayoutType>custom</classpathLayoutType> <customClasspathLayout>  
                                lib/$${artifact.groupId}.$${artifact.artifactId}.$${artifact.extension} </customClasspathLayout> --> 
                        </manifest> 

                        <manifestEntries> 
                            <Class-Path>./</Class-Path> 
                        </manifestEntries> 

                     </archive> 
                     <excludes> 
                         <exclude>config/**</exclude> 
                     </excludes> 
                 </configuration> 
             </plugin>

             <plugin> 
                 <artifactId>maven-assembly-plugin</artifactId> 
                 <configuration> 
                     <!-- not append assembly id in release file name --> 
                     <appendAssemblyId>false</appendAssemblyId> 
                     <descriptors> 
                         <descriptor>src/main/build/package.xml</descriptor> 
                     </descriptors> 
                 </configuration> 
                 <executions> 
                     <execution> 
                         <id>make-assembly</id> 
                         <phase>package</phase> 
                         <goals> 
                             <goal>single</goal> 
                         </goals> 
                     </execution> 
                 </executions> 
              </plugin>
        </plugins>
    </build>
  • 写回答

6条回答 默认 最新

  • devmiao 2016-10-23 10:06
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算