我在 Java、SpringBoot 和 Maven 方面的工作不多。我已经针对上述问题浏览了几篇文章,但没有什么接近我的情况
我在 Windows 10 上使用 Maven 和 JDK1.8.0_172
编译和打包 SpringBoot 项目
然后我将这个打包的 war 部署到 Linux 服务器(RHEL with JDK1.8.0_201 and Tomcat 8
)
当我点击 URL http://localhost:8080/MyApp 时,tomcat 错误,我在 Tomcat 日志中没有看到任何错误
我不确定我做错了什么。非常感谢任何帮助
来自 Tomcat 服务器的错误
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
POM.xml 文件
<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.htc.myapp.main</groupId>
<artifactId>SpringProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<dependencies>
<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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.bmc.remedy</groupId>
<artifactId>remedyapi</artifactId>
<version>8.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/remedyapi-8.1.jar</systemPath>
</dependency>
<!-- JSTL tag lib -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<!-- <dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency> -->
<!-- Tomcat for JSP rendering -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<!-- <dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency> -->
<!--
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency> -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.3</version>
</dependency> -->
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-client -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
</dependencies>
<build>
<finalName>MyApp</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
<procedure><packaging>war</packaging></properties>
</project>
编辑
我安装了 Tomcat 7 并且能够打开该应用程序。但是,对应用程序调用一些操作会抛出“出错了”
查看 Tomcat 日志,似乎数据库连接存在一些问题
日志错误
2019-06-19 12:42:55.943 ERROR 20177 --- [bio-8080-exec-3] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: No suitable driver found for jdbc:jtds:sqlserver://10.xxx.xxx.xxx:1433/MyDatabase;user=username;password=pwd
我将 jtds-1.3.1.jar 复制到 $TOMCAT_instance/lib 目录并尝试使用以下数据库设置,但没有有效
db_LMS.url=jdbc:jtds:sqlserver://10.xxx.xxx.xxx:1433;databaseName=MyDatabase;integratedSecurity=true;user=username;password=pwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
db_LMS.url=jdbc:jtds:sqlserver://10.xxx.xxx.xxx:1433/MyDatabase;user=username;password=pwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
非常感谢在此问题上的任何帮助
最佳答案
在 $TOMCAT_HOME/conf/server.xml 中添加以下内容解决了问题
默认情况下,Tomcat 禁用加载 Java 驱动程序文件以防止内存泄漏问题
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" driverManagerProtection="false" />
关于java - Tomcat 错误 : The origin server did not find a current representation for the target resource or is not willing to disclose that one exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56655691/