My Springboot Application works fine on my Local Server but returns 404 when hosted to my DailyRazor Tomcat Server

huangapple go评论93阅读模式
英文:

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文件:

  1. buildscript {
  2. repositories {
  3. maven {
  4. url "https://plugins.gradle.org/m2/"
  5. }
  6. }
  7. dependencies {
  8. classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.2.RELEASE"
  9. classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
  10. }
  11. }
  12. plugins {
  13. id 'war'
  14. }
  15. group 'com.teamtreehouse'
  16. version '1.0-SNAPSHOT'
  17. allprojects {
  18. apply plugin: 'maven'
  19. apply plugin: "io.spring.dependency-management"
  20. group = 'com.wnp'
  21. version = '6.5.0-SNAPSHOT'
  22. }
  23. apply plugin: 'java'
  24. apply plugin: "org.springframework.boot"
  25. sourceCompatibility = 1.8
  26. targetCompatibility = 1.8
  27. repositories {
  28. mavenCentral()
  29. }
  30. dependencies {
  31. implementation 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.1.0'
  32. compile 'org.springframework.boot:spring-boot-starter-web'
  33. compile 'org.springframework.boot:spring-boot-starter-data-jpa'
  34. compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
  35. compile 'org.springframework.boot:spring-boot-starter-security'
  36. implementation 'org.springframework.boot:spring-boot-starter-mail:2.2.2.RELEASE'
  37. compile group: 'org.apache.maven.plugins', name: 'maven-surefire-plugin', version: '2.22.2'
  38. implementation 'org.ocpsoft.prettytime:prettytime:3.2.7.Final'
  39. compile 'com.h2database:h2:1.4.191'
  40. compile 'com.h2database:h2'
  41. compile 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5'
  42. testCompile group: 'junit', name: 'junit', version: '4.11'
  43. compile 'org.hashids:hashids:1.0.1'
  44. compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'
  45. testImplementation group: 'junit', name: 'junit', version: '4.11'
  46. implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.131'
  47. testImplementation 'software.amazon.awssdk:s3:2.17.102'
  48. runtimeOnly 'software.amazon.awssdk:bom:2.17.102'
  49. }

此外,当我检查我的Tomcat 8日志时,这是我看到的错误消息:

  1. java.lang.NoClassDefFoundError: Could not initialize class org.apache.tomcat.util.buf.B2CConverter
  2. at org.apache.catalina.connector.CoyoteAdapter.parsePathParameters(CoyoteAdapter.java:1036)
  3. at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:786)
  4. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:529)
  5. at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:827)
  6. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
  7. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
  8. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
  9. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  10. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  11. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  12. at java.lang.Thread.run(Thread.java:745)
  13. ERROR ajp-nio-0.0.0.0-9679-ClientPoller-1 org.apache.tomcat.util.net.NioEndpoint -
  14. 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.

  1. @SpringBootApplication
  2. @EnableCaching
  3. public class Run extends SpringBootServletInitializer {
  4. private static SessionFactory sessionFactory = SessionFactoryCreator.createSessionFactory();
  5. public static Session getSession() {
  6. return sessionFactory.openSession();
  7. }
  8. public static void main(String[] args) {
  9. SpringApplication.run(Run.class, args);
  10. }
  11. @Override
  12. protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  13. return application.sources(Run.class);
  14. }
  15. }

Here is my build.gradle file:

  1. buildscript {
  2. repositories {
  3. maven {
  4. url "https://plugins.gradle.org/m2/"
  5. }
  6. }
  7. dependencies {
  8. classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.2.RELEASE"
  9. classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
  10. }
  11. }
  12. plugins {
  13. id 'war'
  14. }
  15. group 'com.teamtreehouse'
  16. version '1.0-SNAPSHOT'
  17. allprojects {
  18. apply plugin: 'maven'
  19. apply plugin: "io.spring.dependency-management"
  20. group = 'com.wnp'
  21. version = '6.5.0-SNAPSHOT'
  22. }
  23. apply plugin: 'java'
  24. apply plugin: "org.springframework.boot"
  25. sourceCompatibility = 1.8
  26. targetCompatibility = 1.8
  27. repositories {
  28. mavenCentral()
  29. }
  30. dependencies {
  31. // https://mvnrepository.com/artifact/io.spring.dependency-management/io.spring.dependency-management.gradle.plugin
  32. implementation 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.1.0'
  33. // 'io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE'
  34. compile 'org.springframework.boot:spring-boot-starter-web'
  35. compile 'org.springframework.boot:spring-boot-starter-data-jpa'
  36. compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
  37. compile 'org.springframework.boot:spring-boot-starter-security'
  38. // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail
  39. implementation 'org.springframework.boot:spring-boot-starter-mail:2.2.2.RELEASE'
  40. compile group: 'org.apache.maven.plugins', name: 'maven-surefire-plugin', version: '2.22.2'
  41. implementation 'org.ocpsoft.prettytime:prettytime:3.2.7.Final'
  42. // compile 'org.springframework:spring-orm'
  43. // compile group: 'org.hibernate', name: 'hibernate-core'
  44. // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat
  45. // providedRuntime group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.7.5'
  46. // compile 'org.apache.tomcat:tomcat-dbcp:8.0.32'
  47. compile 'com.h2database:h2:1.4.191'
  48. compile 'com.h2database:h2'
  49. compile 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5'
  50. testCompile group: 'junit', name: 'junit', version: '4.11'
  51. compile 'org.hashids:hashids:1.0.1'
  52. // compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.12.RELEASE'
  53. // compile group: 'org.thymeleaf', name: 'thymeleaf', version: '3.0.12.RELEASE'
  54. compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'
  55. testImplementation group: 'junit', name: 'junit', version: '4.11'
  56. implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.131'
  57. // https://mvnrepository.com/artifact/software.amazon.awssdk/s3
  58. testImplementation 'software.amazon.awssdk:s3:2.17.102'
  59. // https://mvnrepository.com/artifact/software.amazon.awssdk/bom
  60. runtimeOnly 'software.amazon.awssdk:bom:2.17.102'
  61. }

Furthermore, when I check I my tomcat 8 logs, this is the error message that I am seeing.

  1. java.lang.NoClassDefFoundError: Could not initialize class org.apache.tomcat.util.buf.B2CConverter
  2. at org.apache.catalina.connector.CoyoteAdapter.parsePathParameters(CoyoteAdapter.java:1036)
  3. at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:786)
  4. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:529)
  5. at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:827)
  6. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
  7. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
  8. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
  9. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  10. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  11. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  12. at java.lang.Thread.run(Thread.java:745)
  13. ERROR ajp-nio-0.0.0.0-9679-ClientPoller-1 org.apache.tomcat.util.net.NioEndpoint -
  14. 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.

huangapple
  • 本文由 发表于 2023年6月13日 11:38:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76461552.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定