漠北空城 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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题