恶心自己,成全他人。
背景:
搭建一套开发框架。
结构如下:
分工:
frame_base:是一个pom,主要用于管理jar包
frame_util:是工具类集合
frame_dao:存放的是mybatis的工具类
业务模块:
web
module:service和service-impl的父类
service:接口
service-impl:接口实现类
根据上图搭建好结构,然后进行打包
顺序如下:
1.frame_base:
打包报错:提示找不到nexus,百度,google之后,找到了问题,如下:
这是frame_base中pom.xml的配置
里面配置的私服地址id为nexus,提示nexus找不到,可能是私服中的setting.xml出现问题。<!-- 设定团队持续集成发布包服务器 --> <distributionManagement> <repository> <id>nexus</id> <url>http://${maven.local.server}/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>nexus</id> <url>http://${maven.local.server}/nexus/content/repositories/snapshots</url> <uniqueVersion>false</uniqueVersion> </snapshotRepository> </distributionManagement>
setting.xml里面的认证内容如下:
果然没有nexus,添加后,打包成功。<!-- 添加认证 --> <server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server> <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server> <server> <id>deployment</id> <username>admin</username> <password>admin123</password> </server> <span style="color:#FF0000;"><server> <id>nexus</id> <username>admin</username> <password>admin123</password> </server></span> </servers>
2.frame_util:
打包frame_util报错,如下:
找不到ImageFormatException,JPEGCodec,JPEGImageEncoder,百度,谷歌之后,解决方法如下:在frame_base的pom文件中的plugin标签下添加:
<compilerArguments> <verbose /> <!-- 添加jre位置 --> <bootclasspath>${JAVA_HOME}/lib;${JAVA_HOME}/jre/lib/rt.jar;${JAVA_HOME}/jre/lib/jce.jar</bootclasspath> </compilerArguments>
添加后pom文件配置如下:
<!-- 编译打包之后绑定源码 --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <compilerArguments> <verbose /> <!-- 添加jre位置 --> <bootclasspath>${JAVA_HOME}/lib;${JAVA_HOME}/jre/lib/rt.jar;${JAVA_HOME}/jre/lib/jce.jar</bootclasspath> </compilerArguments> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.1.2</version> <executions> <execution> <id>attach-sources</id> <phase>verify</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <!-- 打包时跳过不执行测试用例 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.17</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build>
3.frame_dao,有了之前的躺雷,frame_dao打包成功。
以下是犯二的地方。
成功打包后,我想是不是可以把service和service-impl也打成包,给其他项目使用。
1.打service包,OK
2.打service-impl包,OK
3.关闭service和service-impl项目,用web项目直接应用service和service-imp。
4.启动web,提示出错:找不到service @Autowired不成功,百思不得其解(钻牛角),看了下web项目中的结构,已经把service和service-impl引入进去了。但是就是不能启动
5.删除service和service-impl的包,使用引用项目的方式,启动成功。
6.结论猜想,在service模块中需要将service托管给spring去管理,打成jar包之后,不再使用同一个spring容器,找不到service。