spring boot + maven 做 分离式lib下jar包和项目下resource 配置文件分离。
1:分离lib主要是因为能够快速发布项目,如果新增jar包情况下,只要将新打包的项目jar包文件上传服务器即可,由于第一次已经上传,后续就无需再上传。分离后的项目jar包很小,可以减小到KB 级别。
2:分离resource 下配置文件,如果需要调整配置文件,无需重新打包上传,只要将项目 重启即可,当然可能有人说,可以使用第三方插件来做,比如百度的disconf 和 apollo等,这些都是分布式文件配置中心,无需重启服务。这些方案都可以,也是依据项目的业务来做各自的取舍。
下面看代码:demo源码见附件,现在这个不知道啥情况,上传不了,垃圾了。
百度云下载地址:链接:https://pan.baidu.com/s/1kYTX3tMGT3YP91s-FXLiOw&shfl=sharepset
提取码:57cv
spring.application.name= /demo server.servlet.context-path=/demo server.port=8080 spring.profiles.path=D:/config
@Slf4j @SpringBootApplication @PropertySource(value = "file:${spring.profiles.path}/demo.properties") public class DemoApplication { @Value("${demo}") private String value; public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @PostConstruct public void init() { log.info("默认环境参数:{}",value ); }
maven 配置
<build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> <!-- 打包时排除配置文件 --> <excludes> <exclude>**/*.properties</exclude> <exclude>**/*.xml</exclude> <exclude>**/*.yml</exclude> </excludes> </resource> </resources> <plugins> <!--<plugin>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-maven-plugin</artifactId>--> <!--</plugin>--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <fork>true</fork> <skip>true</skip> <executable>C:\Program Files\Java\jdk1.8.0_191\bin\javac.exe</executable> </configuration> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <useUniqueVersions>false</useUniqueVersions> <mainClass>com.example.demo.DemoApplication</mainClass> </manifest> <manifestEntries> <Class-path>./</Class-path> </manifestEntries> </archive> <excludes> <exclude>*.properties</exclude> <exclude>config/**</exclude> <exclude>*.xml</exclude> <exclude>*.yml</exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <!--<version>3.1.1</version>--> <executions> <execution> <id>copy</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory> ${project.build.directory}/lib </outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> 需要注意的地方:这里打包的时候会忽略所有的配置文件,在启动的时候就要指定主要的配置文件了 java –jar -Dspring.config.location=xxx/xxx/xxxx.properties xxxx.jar
<excludes> <exclude>*.properties</exclude> <exclude>config/**</exclude> <exclude>*.xml</exclude> <exclude>*.yml</exclude> </excludes>
相关推荐
springboot 的maven依赖包,含有所有maven依赖,网络不好的可以来下。压缩包3.
基于Springboot+mybatis的maven项目
springboot maven引用sqlserver jdbc,亲测可用,从此告别本地手动引入
springboot构建maven多模块项目,这个示例完成了消费者和服务提供者之间的关系调用
springboot+maven整合
这是一个springboot项目,里面有项目和数据库,我自己写的,刚学springboot,这个项目里有增删查,修改还没有做,以后有机会补上,有不懂的可以一起探讨!
springboot(web项目,非maven)
Springboot 打Jar包,Maven完美解决本地Jar包自动打入Springboot Jar包中
Spring Boot项目使用maven-assembly-plugin根据不同环境打包成tar.gz或者zip
SpringBoot官方版Maven,已重新配置阿里云镜像,亲测有效,无需再手动配置镜像,挂载在Eclipse上会自动更新补齐Maven,下载速度保证快(由于更新后体积会变大,建议不要安装在C盘)。
springboot+mybatis+maven+mysql基础适合刚入门的爱好者去实践搭建的方法,直接运行就行。
springboot maven引用oracle jdbc。 亲测可用
springboot 的maven依赖包,含有所有maven依赖,网络不好的可以来下。压缩包4.
sprintboot maven 打包分离lib jar 资源文件 properties xml yml 详细信息查看我的博客 https://mp.csdn.net/postedit/80274087 java -jar -cp 启动
springboot完整maven项目,包括打成的war包以及所需jar包,涵盖redis数据库,eacache缓存,quartz任务调度,登录拦截器filter,跨域处理,默认首页设置,template模板初始化
常用的应用场景是项目需要部署到客户机器上,一定程度上防止代码泄露。 ProGuard 是一个混淆代码的开源项目,它的主要作用是混淆代码,ProGuard 包括以下 4 个功能: 压缩(Shrink):检测并移除代码中无用的类、字段...
总结了我花了一周配置好jenkins的一些坑 这些东西都是自己话时间弄的 网上搜不到答案哟 随便一个坑都能卡几天~~如果有疑问可以留言看到就回
idea+springBoot+maven 搭建项目 配置Oracle mybatis简易配置及数据查询
本项目是基于springboot + maven + mysql 开发的实现增删改查demo,希望能够帮助大家
当前案例中包含一整套的代码和word文档,非常适合新手... 主要是通过maven打包加载不同环境的properties文件 然后将对于的属性绑定到指定的实体对象中;然后通过调用接口可以看到加载不同环境控制台打印的内容是不一样的