如何在每次更改静态资源时停止在Tomcat服务器上运行的Spring Boot项目重新部署它?

时间:2018-06-08 23:06:03

标签: spring-boot tomcat web web-deployment

我有Maven Spring Boot项目,我配置为在Tomcat 8.5服务器上运行。 我在Eclipse Java EE IDE中运行并开发它。

pom.xml是:

df.createOrReplaceTempView("position_table")

spark.sql("""
    select id, concat_ws(',', position.coordinates) as position_coordinates
    from position_table
  """).
  show(false)
//+-----+--------------------+
//|id   |position_coordinates|
//+-----+--------------------+
//|11700|48.597315,-43.206085|
//|11800|49.611254,-43.90223 |
//+-----+--------------------+

application.properties是(用*****替换敏感数据):

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ca.gatin</groupId>
    <artifactId>todoapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>TodoApp</name>
    <description>Cloud TodoApp Server</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.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-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                  <source>1.7</source>
                  <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Tomcat server.xml是:

############################
#                          #
#  Logger Configuration    #
#                          #
############################
# Log Level: ERROR, WARN, INFO, DEBUG or TRACE
#
# logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=INFO


############################
#                          #
# Web Server Configuration #
#                          #
############################
#server.port=9191
#server.contextPath=/api # let it handle in code /api for APIs, /web - for WEB


############################
#                          #
# DataSource Configuration #
#                          #
############################
spring.datasource.url=jdbc:mysql://localhost:3306/todoappdb_dev
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.schema=classpath:/data/schema.sql
spring.datasource.data=classpath:/data/data.sql
# Keep the connection alive if idle for a long time
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1


#####################
#                   #
# JPA Configuration #
#                   #
#####################
# validate:      validate the schema, makes no changes to the database.
# update:        update the schema.
# create:        creates the schema, destroying previous data.
# create-drop:   drop the schema at the end of the session.
# none
##
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
# Whether to enable logging of SQL statements.
spring.jpa.show-sql=true 
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.format_sql=true


########################
#                      #
# Application specific #
#                      #
########################
#
#admin - renat
authentication.oauth.adminid.renat=*****
authentication.oauth.secret.renat=*****
authentication.oauth.tokenValidityInSeconds.renat=1800
#
#client - web
authentication.oauth.clientid.web=*****
authentication.oauth.secret.web=*****
authentication.oauth.tokenValidityInSeconds.web=1800

Tomcat设置是: enter image description here

静态Web内容位置是: enter image description here

我无法做的是: 1.每次更改静态资源时停止重新部署整个项目(包括Java和DB部分); 2.查看日志控制台我可以看到Spring Boot启动了两次,所以我希望它只启动一次。

1 个答案:

答案 0 :(得分:0)

试图关注此网站:https://www.logicbig.com/tutorials/spring-framework/spring-boot/restart-exclude.html

我以为我的问题找到了答案,但由于某种原因,我的系统会忽略application.properties spring.devtools.restart.exclude setup。

所以解决问题的方法就是我将我的Web App HTML / CSS / JS内容从\ src \ main \ resources \ static移到了\ src \ main \ webapp文件夹。

但是“Spring Boot开始两次”的问题仍然存在。任何帮助对我都有好处。