1、SpringBoot打成jar形式,xml配置如下,主要是高亮部分,其他作为参考
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.dm</groupId> <artifactId>botconf</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> #高亮 <name>botconf</name> <description>bot config</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <skiptests>true</skiptests> <resource.delimiter>#</resource.delimiter> <jackson.version>2.11.0</jackson.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.8.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.8.0</version> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.22</version> </dependency> <!--MySQL数据库驱动--> <dependency> <groupId>javax.jms</groupId> <artifactId>javax.jms-api</artifactId> <version>2.0.1</version> </dependency> <dependency> <groupId>com.caucho</groupId> <artifactId>hessian</artifactId> <version>4.0.38</version> </dependency> <!-- json schema 转换 fge --> <dependency> <groupId>com.github.fge</groupId> <artifactId>json-schema-validator</artifactId> <version>2.2.6</version> </dependency> <!-- 解决FluentIterable.class找不到问题 --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>26.0-jre</version> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.0</version> </dependency> <!-- mybatis-plus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.0</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-support</artifactId> <version>2.3</version> </dependency> <!--<dependency>--> <!--<groupId>com.baomidou</groupId>--> <!--<artifactId>mybatis-plus-extension</artifactId>--> <!--<version>3.4.0</version>--> <!--</dependency>--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.1.6</version> </dependency> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>1.3.0.Final</version> </dependency> <!-- 解决springboot 项目使用 lombok 插件后,添加 mapstruct 插件,maven 编译时 mapstruct 插件不起作用 --> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-jdk8</artifactId> <version>1.3.0.Final</version> </dependency> <dependency> <groupId>com.smart</groupId> <artifactId>smart-sso-client</artifactId> <version>1.2.4</version> <exclusions> <exclusion> <artifactId>spring-session-data-redis</artifactId> <groupId>org.springframework.session</groupId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins>#高亮开始 <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> </configuration> </plugin> </plugins>#高亮结束 <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.txt</include> <include>**/*.yml</include> <include>**/*.xml</include> <include>**/application-${spring.profiles.active}.properties</include> </includes> <filtering>true</filtering> </resource> </resources> <finalName>botconf-${spring.profiles.active}</finalName> </build> <profiles> <profile> <id>dev</id> <properties> <spring.profiles.active>dev</spring.profiles.active> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <spring.profiles.active>test</spring.profiles.active> </properties> </profile> </profiles> </project>
2、application.yml配置文件如下(含MybatisPlus配置)
server:
port: 9900
servlet.context-path: /botconf
# 驱动配置信息
spring:
profiles:
active: #spring.profiles.active#
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${dbs.database.host}:${dbs.database.port}/${dbs.database.databasename}?characterEncoding=UTF-8
username: ${dbs.database.username}
password: ${dbs.database.password}
initialSize: 5 # 初始化大小,最小,最大
minIdle: 5
maxActive: 500
maxWait: 60000 # 配置获取连接等待超时的时间
timeBetweenEvictionRunsMillis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
minEvictableIdleTimeMillis: 300000 # 配置一个连接在池中最小生存的时间,单位是毫秒
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
mybatis-plus:
type-aliases-package: com.dm.repository.entity #MyBaits 别名包扫描路径,通过该属性可以给包中的类注册别名,注册后在 Mapper 对应的 XML 文件中可以直接使用类名,而不用使用全限定的类名(即 XML 中调用的时候不用包含包名)
# mapper-locations: classpath:/com/dm/repository/mapper/*Mapper.xml
global-config:
db-config:
# id-type: auto
# field-strategy: not_empty
# logic-delete-field: flag # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2)
# logic-delete-value: 0 # 逻辑已删除值(默认为 1)
# logic-not-delete-value: 1 # 逻辑未删除值(默认为 0)
db-type: mysql
# refresh: false #Mapper 对应的 XML 文件会自动刷新,更改 XML 文件后,无需再次重启工程,生产环境无需打开
configuration:
map-underscore-to-camel-case: true #是否开启自动驼峰命名规则(camel case)映射,即从经典数据库列名 A_COLUMN(下划线命名) 到经典 Java 属性名 aColumn(驼峰命名) 的类似映射。
cache-enabled: false #是否开启二级缓存
application-dev.properties配置如下
profile=dev dbs.database.host= dbs.database.port=3306 dbs.database.username= dbs.database.password= dbs.database.databasename= spring.redis.host= spring.redis.port=6379 spring.redis.database=9 swagger.enable=true log.pool.corePoolSize=5 log.pool.maxPoolSize=99 log.pool.keepAliveSeconds=300 log.pool.queueCapacity=999 log.pool.threadNamePrefix=Log- #logging.config=classpath:logback.xml logging.level.com.dm.repository.mapper=debug
3、进行maven打包
4、将打包好的jar放到服务器上运行命令
nohup java -jar 项目.jar &
5、将前端放到nginx的html目录,并参照如下修改配置文件nginx.conf
server { listen 80; server_name 127.0.0.1; # 将带有jeecg-boot的访问路径代理到http://127.0.0.1:8091/上面的#context-path/,jeecg-boot/后面的依次替换 location /jeecg-boot/ { proxy_pass http://127.0.0.1:8091/上面的context-path/; proxy_set_header Host 127.0.0.1; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } # 访问80端口,访问到前端页面 location / { root html; index index.html index.htm; if (!-e $request_filename) { rewrite ^(.*)$ /index.html?s=$1 last; break; } } }
6、重启并访问项目