springboot maven
Posted 呆小田
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot maven相关的知识,希望对你有一定的参考价值。
更多信息请从官网获取https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE
1.parent基于自己项目而非spring-boot-starter-parent
目前解决方案
(1)所有的springboot依赖显示写出版本号
(2)plugin显示写出执行目标repackage
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>2.0.1.RELEASE</version> <scope>test</scope> </dependency> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.0.1.RELEASE</version> <configuration> <classifier>exec</classifier> <executable>true</executable> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin>
note: <classifier>exec</classifier>该标签作用是如果有其他项目依赖该项目时,会打成两个jar,一个是xxx.jar(别的项目依赖用)另一个是xxx-exec.jar(部署执行用)
2.idea run没问题,打成jar包执行报资源文件找不到
目前解决方案是拷贝一份资源文件到classes目录下即可
<plugin> <artifactId>maven-resources-plugin</artifactId> <executions> <execution> <id>copy-resources</id> <phase>validate</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/classes</outputDirectory> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin>
如果idea run也报资源文件找不到
(1)检查该文件是否存在resources文件夹内
(2)检查resources文件夹是否为Resources Root 。否则右键Mark Directory As --> Resources Root 即可
以上是关于springboot maven的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot启动报错“Consider defining a bean of type ‘xxx.mapper.UserMapper‘ in your configuration.“(代码片段
maven工程仿springboot手写代码区分开发测试生产
全栈编程系列SpringBoot整合Shiro(含KickoutSessionControlFilter并发在线人数控制以及不生效问题配置启动异常No SecurityManager...)(代码片段
maven web项目的web.xml报错The markup in the document following the root element must be well-formed.(代码片段
SpringBoot中表单提交报错“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“(代码片段