【问题标题】:Spring Boot JAR Not Working on Windows ServerSpring Boot JAR 在 Windows Server 上不起作用
【发布时间】:2017-10-12 18:52:41
【问题描述】:

我有一个 Web 应用程序在本地机器上运行良好,但是当我尝试将相同的 JAR 部署到我的一台 Windows 服务器时,它运行不正常。 它作为服务运行,但是当我尝试通过浏览器访问 Web 应用程序时,它不会呈现任何内容,是否需要它们的任何其他配置才能在 Windows 服务器上部署和升级它,任何帮助都将非常重要很明显,我正在使用 Web 应用程序的堆栈如下所述。

Spring Boot - 1.4.7.RELEASE

Java - 版本 - 1.8

MySQL - 5.7

嵌入式 Tomcat 版本 - 8.5.15

@SpringBootApplication
@ComponentScan(basePackages = "com.abc.xyz")
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

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

application.properties 文件如下

 #JPA
    #spring.datasource.hikari.username = root
    #spring.datasource.hikari.password = root
    #spring.datasource.hikari.jdbc-url = jdbc:mysql://localhost:3306/dbname?useUnicode=yes&characterEncoding=UTF-8
    #spring.datasource.type = com.zaxxer.hikari.HikariDataSource
    spring.datasource.driverClassName=com.mysql.jdbc.Driver
    spring.datasource.username = root
    spring.datasource.password = xyz
    spring.datasource.url = jdbc:mysql://localhost:3306/dbname?useUnicode=yes&characterEncoding=UTF-8&useSSL=false

    spring.jpa.hibernate.ddl-auto = update
    spring.jpa.show-sql = false
    #spring.jpa.format-sql = true
    spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
    spring.jpa.properties.hibernate.current_session_context_class = org.springframework.orm.hibernate5.SpringSessionContext
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
    #Logging
    logging.level.org.springframework = INFO
    logging.level.org.hibernate = INFO
    logging.level.com.karza = INFO
    logging.file= D:/abc/xyz.log
    # MVC
    #spring.view.prefix=/templates/views/
    #spring.view.suffix=.jsp
    spring.mvc.view.prefix=/WEB-INF/jsp/views/
    spring.mvc.view.suffix=.jsp
    #spring.view.prefix=/WEB-INF/jsp/views/
    #spring.view.suffix=.jsp
    #server
    server.context-path = /
    server.port = 8090
    server.compression.enabled = true
    server.compression.mime-types = application/json,application/xml,text/html,text/xml,text/plain

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

    <groupId>com.abc.xyz</groupId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>ABC</name>
    <description>Demo project for Spring Boot</description>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> 
            </dependency> -->
         <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency> 
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <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-test</artifactId> 
            <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> 
            <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> -->
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>

        <!-- <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> 
            </dependency> -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <!-- <version>1.4.196</version> -->
        </dependency>
        <dependency>
            <groupId>net.sf.flexjson</groupId>
            <artifactId>flexjson</artifactId>
            <version>3.3</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.8.3</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>applicationinsights-web</artifactId>
            <version>1.0.6</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-storage</artifactId>
            <version>5.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>applicationinsights-logging-logback</artifactId>
            <version>1.0.6</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-svc-mgmt</artifactId>
            <version>0.9.7</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-svc-mgmt-compute</artifactId>
            <version>0.9.7</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-svc-mgmt-network</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-svc-mgmt-sql</artifactId>
            <version>0.9.7</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-svc-mgmt-storage</artifactId>
            <version>0.9.7</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-svc-mgmt-websites</artifactId>
            <version>0.9.7</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc-portlet</artifactId>
        </dependency>
    </dependencies>

    <build>
     <plugins>
        <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> 
            </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
            </configuration>
        </plugin>
    </plugins> 
      <!-- <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.4.7.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins> -->
</build>


    <artifactId>ABC</artifactId>
</project>

【问题讨论】:

  • 您是否启用了日志记录?正确配置所有环境变量(尤其是配置文件)。
  • 你能把你的问题加到主课吗
  • @LakatosGyula 是的,一切都已正确定义并且日志记录已启用,您能否对配置文件更加谨慎,我不明白,您所说的配置文件到底是什么意思。从环境变量到配置,一切都定义明确
  • @mrtasln 我已经更新了问题并附上了我的主要课程。
  • 您能否添加有关您的配置的更多详细信息,例如 application.properties ,pom 文件

标签: java spring spring-mvc spring-boot


【解决方案1】:

我刚刚更新了 pom.XML,我将它从 JAR 更新为 war 并将它作为 WAR 运行,它工作了,我执行了它 JAVA -jar APPLICATION_NAME.jar,它就像魅力一样工作。 希望这对其他人也有帮助。

引用拯救我的链接。

https://www.mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/

【讨论】:

    猜你喜欢
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    • 1970-01-01
    • 2016-01-12
    • 2016-11-04
    相关资源
    最近更新 更多