英文:
My Springboot Application works fine on my Local Server but returns 404 when hosted to my DailyRazor Tomcat Server
问题
我正在尝试将我的Spring Boot Hibernate应用程序托管到DailyRazor上的Tomcat服务器上,但我遇到了一个问题。在创建可部署的War文件并将其直接放入webapps文件夹之后,当尝试访问我的网站时,我仍然收到404页面。所有API都返回这个404页面,甚至根API也是如此。
我已经尝试解决这个问题几周了,我已经看到了所有常见的错误,并且我相信我已经正确配置了我的Spring Boot应用程序。我已经重写了configure方法,并确保扩展了SpringBootServletInitializer,但问题仍然存在。由于我是在IntelliJ中创建项目的,所以我是通过在CMD中使用gradlew bootWar来生成war文件的。
这是我的build.gradle文件:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.2.RELEASE"
classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
}
}
plugins {
id 'war'
}
group 'com.teamtreehouse'
version '1.0-SNAPSHOT'
allprojects {
apply plugin: 'maven'
apply plugin: "io.spring.dependency-management"
group = 'com.wnp'
version = '6.5.0-SNAPSHOT'
}
apply plugin: 'java'
apply plugin: "org.springframework.boot"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.1.0'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-mail:2.2.2.RELEASE'
compile group: 'org.apache.maven.plugins', name: 'maven-surefire-plugin', version: '2.22.2'
implementation 'org.ocpsoft.prettytime:prettytime:3.2.7.Final'
compile 'com.h2database:h2:1.4.191'
compile 'com.h2database:h2'
compile 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'org.hashids:hashids:1.0.1'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'
testImplementation group: 'junit', name: 'junit', version: '4.11'
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.131'
testImplementation 'software.amazon.awssdk:s3:2.17.102'
runtimeOnly 'software.amazon.awssdk:bom:2.17.102'
}
此外,当我检查我的Tomcat 8日志时,这是我看到的错误消息:
java.lang.NoClassDefFoundError: Could not initialize class org.apache.tomcat.util.buf.B2CConverter
at org.apache.catalina.connector.CoyoteAdapter.parsePathParameters(CoyoteAdapter.java:1036)
at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:786)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:529)
at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:827)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
ERROR ajp-nio-0.0.0.0-9679-ClientPoller-1 org.apache.tomcat.util.net.NioEndpoint -
java.lang.OutOfMemoryError: Java heap space
英文:
I am trying to host my springboot hibernate application to my tomcat server on DailyRazor but I am encountering an issue. After creating a deployable War file and dropping it in the webapps folder directly, I still receive a 404 page when when trying to access my website. All apis return this 404 page even the root api.
I have been trying to solve this for a few weeks now and I have seen all the common mistakes and I believe that I have configured my springboot application correctly. I have overrided the configure method and I have made sure to extend the SpringBootServletInitializer, but the problem still persists. Since I am creating my project in Intellij, I am generating the war file by using the gradlew bootWar in the CMD.
@SpringBootApplication
@EnableCaching
public class Run extends SpringBootServletInitializer {
private static SessionFactory sessionFactory = SessionFactoryCreator.createSessionFactory();
public static Session getSession() {
return sessionFactory.openSession();
}
public static void main(String[] args) {
SpringApplication.run(Run.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Run.class);
}
}
Here is my build.gradle file:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.2.RELEASE"
classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
}
}
plugins {
id 'war'
}
group 'com.teamtreehouse'
version '1.0-SNAPSHOT'
allprojects {
apply plugin: 'maven'
apply plugin: "io.spring.dependency-management"
group = 'com.wnp'
version = '6.5.0-SNAPSHOT'
}
apply plugin: 'java'
apply plugin: "org.springframework.boot"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/io.spring.dependency-management/io.spring.dependency-management.gradle.plugin
implementation 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.1.0'
// 'io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework.boot:spring-boot-starter-security'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail
implementation 'org.springframework.boot:spring-boot-starter-mail:2.2.2.RELEASE'
compile group: 'org.apache.maven.plugins', name: 'maven-surefire-plugin', version: '2.22.2'
implementation 'org.ocpsoft.prettytime:prettytime:3.2.7.Final'
// compile 'org.springframework:spring-orm'
// compile group: 'org.hibernate', name: 'hibernate-core'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat
// providedRuntime group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.7.5'
// compile 'org.apache.tomcat:tomcat-dbcp:8.0.32'
compile 'com.h2database:h2:1.4.191'
compile 'com.h2database:h2'
compile 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'org.hashids:hashids:1.0.1'
// compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.12.RELEASE'
// compile group: 'org.thymeleaf', name: 'thymeleaf', version: '3.0.12.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'
testImplementation group: 'junit', name: 'junit', version: '4.11'
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.131'
// https://mvnrepository.com/artifact/software.amazon.awssdk/s3
testImplementation 'software.amazon.awssdk:s3:2.17.102'
// https://mvnrepository.com/artifact/software.amazon.awssdk/bom
runtimeOnly 'software.amazon.awssdk:bom:2.17.102'
}
Furthermore, when I check I my tomcat 8 logs, this is the error message that I am seeing.
java.lang.NoClassDefFoundError: Could not initialize class org.apache.tomcat.util.buf.B2CConverter
at org.apache.catalina.connector.CoyoteAdapter.parsePathParameters(CoyoteAdapter.java:1036)
at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:786)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:529)
at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:827)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
ERROR ajp-nio-0.0.0.0-9679-ClientPoller-1 org.apache.tomcat.util.net.NioEndpoint -
java.lang.OutOfMemoryError: Java heap space
答案1
得分: 0
终于成功解决了那个问题。显然问题是我在使用Tomcat 10
。根据一些在线帖子,Tomcat 10
不支持Springboot。将我的Tomcat
版本从10更改为8解决了问题。
英文:
Finally managed to solve that issue. Apparently the problem was that I was using Tomcat 10
. According to some posts online, Tomcat 10
does not support Springboot. Changing my Tomcat
version from 10 to 8 solved the problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论