简体   繁体   English

无法使用嵌入式Tomcat浏览到Spring Boot应用程序

[英]Unable to browse to spring boot application using embedded Tomcat

I am working on a rather large MVC project that used to run (perfectly) with just spring MVC, not spring boot. 我正在研究一个相当大的MVC项目,该项目过去只能(完全)运行于spring MVC,而不是spring boot。 I have finished converting it to spring boot and it runs perfectly in Netbeans and when run as a standalone JAR outside of Netbeans on my development machine. 我已经完成了将其转换为Spring Boot的操作,并且可以在Netbeans中完美运行,并且可以在开发计算机上以NetBeans之外的独立JAR形式运行。

I transported the JAR file to its destination server and everything starts normally according to the console, I get this message: Tomcat started on the port(s): 8081 (HTTP) with context path '/MDHIS' . 我将JAR文件传输到其目标服务器,并且一切都根据控制台正常启动,我收到此消息: Tomcat started on the port(s): 8081 (HTTP) with context path '/MDHIS' However, I am unable to browse to it as I would on my machine with the following URL: http://localhost:8081/MDHIS/ . 但是,我无法像在计算机上那样使用以下URL浏览到它: http://localhost:8081/MDHIS/

I set tomcat to debug mode and it logs some interesting things : 我将tomcat设置为调试模式,它记录了一些有趣的东西:

[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.269] o.a.j.s.JspServlet                       
: JspEngine --> /WEB-INF/views/login.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.270] o.a.j.s.JspServlet                       
:        ServletPath: /WEB-INF/views/login.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.270] o.a.j.s.JspServlet                       
:           PathInfo: null
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.272] o.a.j.s.JspServlet                       
:           RealPath: C:\Users\Administrator\AppData\Local\Temp\tomcat- 
docbase.4901819852507265388.8080\WEB-INF\views\login.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.273] o.a.j.s.JspServlet                       
:         RequestURI: /MDHIS/WEB-INF/views/login.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.274] o.a.j.s.JspServlet                       
:        QueryString: null
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.275] o.a.c.c.C.[.[.[.[jsp]                    
:  Disabling the response for further output
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.277] o.a.c.c.C.[.[localhost]                  
: Processing ErrorPage[errorCode=0, location=/error]
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.315] o.a.j.s.JspServlet                       
: JspEngine --> /WEB-INF/views/error.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.315] o.a.j.s.JspServlet                       
:        ServletPath: /WEB-INF/views/error.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.316] o.a.j.s.JspServlet                       
:           PathInfo: null
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.317] o.a.j.s.JspServlet                       
:           RealPath: C:\Users\Administrator\AppData\Local\Temp\tomcat- 
docbase.4901819852507265388.8080\WEB-INF\views\error.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.318] o.a.j.s.JspServlet                       
:         RequestURI: /MDHIS/WEB-INF/views/error.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.319] o.a.j.s.JspServlet                       
:        QueryString: null
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.319] o.a.c.c.C.[.[.[.[jsp]                    
:  Disabling the response for further output
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.320] o.a.c.c.C.[.[.[. 
[dispatcherServlet]      :  Disabling the response for further output

I watched the docbase folder and no JSPs or classes are ever added to it. 我看着docbase文件夹,并且没有将JSP或类添加到其中。 I am having mixed results of this working or not on different environments / OSes / networks. 我在不同的环境/操作系统/网络上是否有此工作的混合结果。 Has any one ever seen this behavior? 有没有人见过这种行为?

******EDIT****** ******编辑******

POM.xml files as requested : 根据要求提供POM.xml文件:

Common project : 共同项目:

<?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.mdenis</groupId>
<artifactId>MDHIS_Common</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
</parent>

<dependencies>

    <!--JAVA-->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
    </dependency>

    <!--SPRING-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
    <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>

    <!--MICROSOFT-->
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
    </dependency>

    <!--HIBERNATE-->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
    </dependency>

    <!--HAPI-->
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-base</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v26</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v25</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v24</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v231</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v23</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v22</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v21</artifactId>
        <version>2.3</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <finalName>MDHIS_Common</finalName>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

Web client : 网络客户端:

<?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.mdenis</groupId>
<artifactId>MDHIS_WebClient</artifactId>
<version>1.0-SNAPSHOT</version>
<!--<packaging>war</packaging>-->

<name>MDHIS_WebClient</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
</parent>

<dependencies>

    <!--JAVA-->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>8.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.json.bind</groupId>
        <artifactId>javax.json.bind-api</artifactId>
    </dependency> 
    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

    <!--GLASSFISH-->
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.el</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.json</artifactId>
        <version>1.1.3</version>
    </dependency>

    <!--TOMCAT-->
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>

    <!--JASPER REPORTS-->
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>6.7.0</version>
    </dependency>

    <!--SIGAR-->
    <dependency>
        <groupId>org.fusesource</groupId>
        <artifactId>sigar</artifactId>
        <version>1.6.4</version>
    </dependency>

    <!--LOG4J2-->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-1.2-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-jcl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-jul</artifactId>
    </dependency>

    <!--YASSON-->
    <dependency>
        <groupId>org.eclipse</groupId>
        <artifactId>yasson</artifactId>
        <version>1.1.0-SNAPSHOT</version>
    </dependency>

    <!--MDHIS_COMMON-->
    <dependency>
        <groupId>com.mdenis</groupId>
        <artifactId>MDHIS_Common</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

</dependencies>

<repositories>

    <repository>
        <id>java.net-Public</id>
        <name>Maven Java Net Snapshots and Releases</name>
        <url>https://maven.java.net/content/groups/public/</url>
    </repository>
    <repository>
        <id>yasson-snapshots</id>
        <name>Yasson Snapshots repository</name>
        <url>https://repo.eclipse.org/content/repositories/yasson-snapshots</url>
    </repository>

</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

</project>

CONCLUSION 结论

Thanks to everyone that helped! 谢谢大家的帮助! Although it was working fine on some systems when packaged as a JAR file, the change to a WAR file is what fixed it. 尽管将其打包为JAR文件时在某些系统上运行良好,但对WAR文件所做的更改已解决了该问题。 I can sadly no longer run the project in Netbeans because it fails to recognize that a Tomcat server is embedded within itself but everything works perfectly when using java -jar on 2 systems (Windows Server 2016 and Ubuntu LTS 18.04) that were previously not working. 遗憾的是,我无法再在Netbeans中运行该项目,因为它无法识别出Tomcat服务器已嵌入其自身,但是在以前无法正常工作的2个系统(Windows Server 2016和Ubuntu LTS 18.04)上使用java -jar时,一切运行正常。

Thanks 谢谢

Faced with such kind of problem, I would probe what could be environmental differences between local machine (where the app is running fine) and server (where the same app is giving problem). 面对此类问题,我将探讨本地计算机(应用运行良好)和服务器(同一应用存在问题)之间的环境差异。 First few things I would check are as follows: 我要检查的前几件事如下:

  1. Check if the JSP's are getting compiled to the work directory of Tomcat. 检查是否将JSP编译到Tomcat的工作目录中。
  2. Check JAVA_HOME variable picked up by Tomcat. 检查Tomcat拾取的JAVA_HOME变量。
  3. Check if the JDK (and not just JRE) is indeed installed on the machine. 检查计算机上是否确实安装了JDK(而不仅仅是JRE)。
  4. Check if the Java version configured for Tomcat is supported by Spring Boot version used. 检查所使用的Spring Boot版本是否支持为Tomcat配置的Java版本。
  5. Check the dependencies in the effective pom that have the scope "provided", "runtime" or "system". 检查有效pom中范围为“提供”,“运行时”或“系统”的依赖项。

But first and foremost, please refer these JSP Limitations with Spring Boot and note that you need to use a war packaging -- JSPs are not supported when using an executable jar . 但是首先,请参阅Spring Boot的这些JSP限制,并注意您需要使用war包装-使用可执行jar时不支持JSP This executable war will work when launched with java -jar , and will also be deployable to any standard container. java -jar一起启动时,此可执行文件战争将起作用,并且也可部署到任何标准容器。

To create a war packaging, include <packaging>war</packaging> in the pom where the artifact ID is declared. 要创建战争包装,请在声明工件ID的pom中包含<packaging>war</packaging>

You may find this Spring Boot JSP sample useful. 您可能会发现此Spring Boot JSP示例很有用。 This another sample may also be helpful. 另一个示例也可能会有所帮助。

Hope the above inputs lead to a solution. 希望以上输入能够解决问题。

The symptoms described sounds as if the classLoader is not initializing the SpringBoot application class. 所描述的症状听起来好像classLoader没有初始化SpringBoot应用程序类。 SpringBoot starts Tomcat with the provided configs first (and this generally always works), and then attempts to start the SpringBoot Application itself. SpringBoot首先使用提供的配置启动Tomcat(这通常可以正常工作),然后尝试启动SpringBoot应用程序本身。 If the classLoader fails the "the website won't load" comes next. 如果classLoader失败,则接下来是“网站将无法加载”。

Two things you can check for: 您可以检查两件事:

1) Do you use ClassLoader.getSystemClassLoader() ? 1)您是否使用ClassLoader.getSystemClassLoader() Don't because it doesn't support SpringBoot structure (nested jars). 不,因为它不支持SpringBoot结构(嵌套jar)。

2) Are you using java.util.Logging anywhere in your application? 2)您是否在应用程序java.util.Logging任何地方使用java.util.Logging Don't because it uses ClassLoader.getSystemClassLoader() 不需要,因为它使用ClassLoader.getSystemClassLoader()

You can read more about this here: https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#executable-jar-restrictions 您可以在这里阅读有关此内容的更多信息: https : //docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#executable-jar-restrictions

I suppose there is a third; 我想还有三分之一。

3) check version compatibility of dependencies (since this is MVC to Boot) https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#appendix-dependency-versions 3)检查依赖项的版本兼容性(因为这是MVC引导) https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#appendix-dependency-versions

Best of luck. 祝你好运。

This is less an answer and more of a path that should lead to eventual success. 这不是一个答案,而更多是一条通往最终成功的道路。 I would start with a sample "Spring Boot Embedded Tomcat" project. 我将从一个示例“ Spring Boot Embedded Tomcat”项目开始。 Dev Zone has one here. 开发区在这里有一个。 Another example is here. 另一个例子在这里。 While those are far too long to include here, any other working sample should be fine as well. 尽管这些内容太长,无法在此处包含,但其他任何工作示例也应该很好。

Get that running in your environment that currently fails. 使它在当前失败的环境中运行。

Next, add your specifics. 接下来,添加您的详细信息。 If you can do this in separate 'chunks' that would be even better as you can then see what part you add breaks things. 如果您可以在单独的“块”中执行此操作,那么效果会更好,然后您可以看到添加的部分会破坏事情。

Finally, I echo Randy's first thought in his reply - this is likely a classpath issue. 最后,我在兰迪的回答中回应了兰迪的第一个想法-这很可能是类路径问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM