多环境配置与应用
多环境开发
在实际的开发中,我们连接的数据库不唯一,一般都是开发时一个数据库,测试时一个库,实际生产一个库,这时候我们就需要使用多环境开发。
我们可以设定属性activation activeByDefault来设置默认环境。
<!-- 配置多环境-->
<profiles>
<!--开发环境-->
<profile>
<id>env_dep</id>
<properties>
<jdbc.url>jdbc:mysql://127.1.1.1:3306/thesecondcast?useSSL=false</jdbc.url>
</properties>
<!--设置是否为默认环境-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!--生产环境-->
<profile>
<id>env_pro</id>
<properties>
<jdbc.url>jdbc:mysql://127.2.2.2:3306/thesecondcast?useSSL=false</jdbc.url>
</properties>
</profile>
<!--测试环境-->
<profile>
<id>env_test</id>
<properties>
<jdbc.url>jdbc:mysql://127.3.3.3:3306/thesecondcast?useSSL=false</jdbc.url>
</properties>
</profile>
</profiles>
此时运行,连接的则是开发环境设置的url。
但这般设置,想要修改的时候很麻烦,每次都得设置默认启动项,实际开发有一种更简便的方法。根据ID来启动。
在IDEA打开Maven侧栏,点击此按钮,输入上面的指令,就可以启动了。
跳过测试
点击此按钮,跳过所有的测试。
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>false</skipTests>
<!-- 排除不参与的测试内容-->
<excludes>
<exclude>**/BookServiceTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
此项目只有BookServiceTest 一个测试类,exclude后执行应该不执行测试方法。
还可使用指令来跳过测试,以后跳过测试指令是最常用的:
私服
(目前并未下载到Nexus软件,还未能好好学习私服)
私服是一台独立的服务器,用于解决团队内部的资源共享与资源同步问题。
Nexus: