1) 将 system scope 的jar 安装到自己的本地mvn rep, 执行一次即可 ,可以在idea or eclipse 里面执行 run maven
2) @Primary
@Bean(name="postgresSqlSessionFactory")
public SqlSessionFactory postgresSqlSessionFactory(@Qualifier("postgresDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean b = new SqlSessionFactoryBean();
b.setDataSource(dataSource);
b.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources("classpath*:/com/xxx/yyy/db/**/*Mapper.xml")); //一定不要写成 **/*Mapper.xml springboot 会无法找到 依赖jar 里面的xml
b.setConfigLocation(new PathMatchingResourcePatternResolver()
.getResources("classpath:mybatis-config-postgres.xml")[0]);
return b.getObject();
}
3) 编译: -DisCloudVersion=true or -DisCloudVersion=false 来区分 cloud 和onpromise 编译
4) 部署:
将 *onpromise.jar 放置在一个目录(当前就是这么干的),同级目录新建 lib 目录,将编译生成的 lib 里面的jar 拷贝过去即可, 启动方式和现在一致, 记得启动命令将 -exec.jar 后缀改成 -onpromise.jar
5) 重点讲解:
<profile>
<id>onpromise</id>
<activation>
<property>
<name>isCloudVersion</name>
<value>false</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> // 完成依赖 jar 的 copy
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/../../lib</outputDirectory>
<includeScope>compile</includeScope>
<includeScope>provided</includeScope>
<includeScope>system</includeScope>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
<archive>
<manifest>
<mainClass>com.xxx.yyy.Application</mainClass> // 完成依赖 MANIFEST Class-Path 的赋值
<classpathPrefix>./lib</classpathPrefix>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<excludes>
<exclude>bin/**</exclude>
<exclude>config/**</exclude>
<exclude>logs/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.xxx.yyy.Application</mainClass>
<includeSystemScope>true</includeSystemScope>
<layout>ZIP</layout>
<includes>
<include>
<groupId>nothing</groupId> // 去除对 依赖 jar 的整体打包
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>onpromise</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<filtering>true</filtering>
<directory>**</directory>
<excludes>
<exclude>**/application.properties</exclude>
<exclude>**/*.proto</exclude>
</excludes>
</resource>
</resources>
</build>
</profile>