Spring Boot独立应用程序使用Tomcat忽略application.properties中的server.port

时间:2016-09-26 13:08:37

标签: java spring spring-boot

我有一个Spring Boot Web应用程序,我试图将其作为嵌入了Tomcat的独立应用程序运行。

应用程序运行正常,但在默认的tomcat端口上运行。我尝试编辑我的application.properties文件并定义' server.port = 80',但是当应用程序执行时,这似乎被忽略了。

这是我的application.properties文件;

server.port=8090
#spring.profiles.active=development

#Application properties
intranet.version = 1.0.21

# MVC properties
spring.mvc.view.prefix = /WEB-INF/view/
spring.mvc.view.suffix = .jsp

spring.jpa.show-sql = false
#spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.EJB3NamingStrategy

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

# Storage
storage.path=/tmp/

# Logging
logging.level.org.springframework = ERROR
logging.level.com.nationallocums = DEBUG
logging.level.org.hibernate = FATAL

# Email
spring.mail.host = smtp.mandrillapp.com
spring.mail.username = jj
spring.mail.password = jjj
spring.mail.port=587
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.starttls.enable = true

# Job Mailbox
job.mailbox.host = jjjj
job.mailbox.type = jjj
job.mailbox.username = jjj
job.mailbox.password = jjj

这是我的POM文件;

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.nationallocums</groupId>
    <artifactId>intranet</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1</version>
    <name>National Locums Intranet</name>
    <url>http://maven.apache.org</url>

    <properties>
        <java-version>1.8</java-version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        -->
        <!--
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.37</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>
        <!-- Apache Commons FileUpload -->

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <!-- Apache Commons IO -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>

        <!-- Open CSV -->
        <dependency>
            <groupId>net.sf.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>2.3</version>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.4</version>
        </dependency>

        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.9.2</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>intranet</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

最后,我的Application.class

@SpringBootApplication
@EnableScheduling
public class Application extends SpringBootServletInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        servletContext.addListener(new SessionListener());
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

在IntelliJ中运行应用程序时,这是控制台输出。

2016-09-26 14:04:36.707  INFO 25829 --- [           main] com.nationallocums.Application           : Starting Application on Shauns-iMac.local with PID 25829 (started by shaunsheppard in /Users/shaunsheppard/Projects/National Locums/NatLocApp)
2016-09-26 14:04:36.712 DEBUG 25829 --- [           main] com.nationallocums.Application           : Running with Spring Boot v1.4.0.RELEASE, Spring v4.3.2.RELEASE
2016-09-26 14:04:36.713  INFO 25829 --- [           main] com.nationallocums.Application           : No active profile set, falling back to default profiles: default
2016-09-26 14:04:41.101  INFO 25829 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-09-26 14:04:41.105  INFO 25829 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.4 

我希望控制台输出确认Tomcat在端口80上运行,但它没有确认。

0 个答案:

没有答案