SpringBoot部署linux
nohup java -jar spring-app.jar &
&的意思是在后台运行, 什么意思呢? 意思是说, 当你在执行 java -jar spring-app.jar & 的时候, 即使你用ctrl C, 那么tomact照样运行(因为对SIGINT信号免疫)。 但是要注意, 如果你直接关掉shell后, 那么, tomact进程同样消失。 可见, &的后台并不硬(因为对SIGHUP信号不免疫)。
nohup的意思是忽略SIGHUP信号, 所以当运行nohup java -jar spring-app.jar的时候, 关闭shell, 那么tomcat进程还是存在的(对SIGHUP信号免疫)。 但是, 要注意, 如果你直接在shell中用Ctrl C, 那么, tomcat进程也是会消失的(因为对SIGINT信号不免疫)
所以, &和nohup没有半毛钱的关系, 要让进程真正不受shell中Ctrl C和shell关闭的影响, 那该怎么办呢? 那就用nohua java -jar spring-app.jar &吧, 两全其美。问题1:在做spring+mybatis时,自动扫描都配置正确了,却在运行时出现了如下错误。后来查看target/classes/.../dao/文件夹下,发现只有mapper的class文件,而没有xml文件,将对应的xml文件放到这个文件夹下运行就不会出现下面的错误。说明出现这个错误的原因是maven编译时没有将xml文件放进去。
问题2:resources文件夹中的配置文件都编译不到classes中去了。
问题1解决方法:
在pom.xml中添加如下代码:
<build> ... <resources> <resource> <directory>src/main/javadirectory> <includes> <include>**/*.xmlinclude> includes> <filtering>truefiltering> resource> resources> ... build>
同理,问题2解决方法:
<build> ... <resources> <resource> <directory>src/main/resourcesdirectory> <includes> <include>**/*.xmlinclude> <include>**/*.propertiesinclude> includes> <filtering>truefiltering> resource> resources> ... build>
如果上述方法还出现资源文件编译不到classes文件的问题的情况,采用如下方法:
因为xml等都属于resources文件,所以将xml文件按照包结构挪到resources文件夹下即可。
org.apache.maven.plugins
maven-surefire-plugin
true
mvn clean package -Dmaven.test.skip=true
总结:当打包出现异常时,首先检测自己的maven结构是否是符合maven默认的规范,如果自己新增了资源文件,比如原先是src/main/java 后来自己又新增了src/main/basic文件夹时需要在pom.xml文件中进行相应的配置
<
build
>
<
sourceDirectory
>src/main/java
sourceDirectory
>
<
testSourceDirectory
>src/test/java
testSourceDirectory
>
<
resources
>
<
resource
>
<
directory
>src/main/resources
directory
>
resource
>
resources
>
<
testResources
>
<
testResource
>
<
directory
>src/test/resources
directory
>
testResource
>
testResources
>
build
>
<sourceDirectory>只能指定一个源代码目录,不能指定多个,可以使用build-helper-maven-plugin来进行代替
<
build
>
<
plugins
>
<
plugin
>
<
groupId
>org.codehaus.mojo
groupId
>
<
artifactId
>build-helper-maven-plugin
artifactId
>
<
version
>1.8
version
>
<
executions
>
<
execution
>
<
id
>add-source
id
>
<
phase
>generate-sources
phase
>
<
goals
>
<
goal
>add-source
goal
>
goals
>
<
configuration
>
<
sources
>
<
source
>src/java/main
source
>
<
source
>src/java/basic
source
>
sources
>
configuration
>
execution
>
executions
>
plugin
>
plugins
>
build
>
详情也可参考这个:https://blog.csdn.net/majian_1987/article/details/50971301
自己的尝试的pom文件如下:
4.0.0
com.XXX
XXX
0.0.1-SNAPSHOT
jar
XXX
XXX管理平台
org.springframework.boot
spring-boot-starter-parent
2.0.1.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-jdbc
org.apache.tomcat
tomcat-jdbc
com.zaxxer
HikariCP
mysql
mysql-connector-java
runtime
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.2
com.github.pagehelper
pagehelper
5.1.4
org.springframework.boot
spring-boot-starter-test
test
org.projectlombok
lombok
1.16.18
provided
io.springfox
springfox-swagger2
2.7.0
io.springfox
springfox-swagger-ui
2.7.0
ch.qos.logback
logback-classic
org.springframework.boot
spring-boot-starter-data-redis
redis.clients
jedis
biz.paluch.redis
lettuce
4.2.2.Final
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-devtools
true
io.jsonwebtoken
jjwt
0.9.0
com.google.code.gson
gson
2.8.4
org.springframework.boot
spring-boot-starter-security
org.springframework.security.oauth
spring-security-oauth2
2.3.3.RELEASE
org.sitemesh
sitemesh
3.0.1
my-spring-boot
org.springframework.boot
spring-boot-maven-plugin
true
org.apache.maven.plugins
maven-surefire-plugin
true
maven-compiler-plugin
1.8
1.8
UTF-8
${JAVA8_HOME}/bin/javac
org.codehaus.mojo
build-helper-maven-plugin
add-source
generate-sources
add-source
src/main/module
src/main/java
**/*.xml
true
src/main/resources
**
true