你好吗?
我正在做一个Sping Boot 应用程序,我在TomCat上遇到了404错误。我正在使用Maven构建.WAR文件,并使用tomcat 7-maven插件部署到TomCat。我已经阅读了很多与我的上下文非常相似的主题,但我找不到解决方案。我注意到的一点是,当我进行部署时,Spring字母不再显示在TomCat提示符上。
HTTP Status 404 – Not Found
Type Status Report
Message The requested resource [/scim/] is not available
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.64
Print of the error
有些人试图解决这个问题,把extends SpringBootServletInitializer
和
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
return builder.sources(ScimApplication.class);
}
在主课堂上,但我已经做了,没有工作。
我使用mvn clean install
命令编译.war文件,然后执行mvn clean tomcat7:deploy
命令直接部署到TomCat,我已经在tomcat-users.xml上配置了用户,并在Maven的conf文件夹的settings.xml上添加了服务器标记。
即使我进入TomCat的管理器页面,并从那里进行部署,当我尝试localhost:8080/scim时,我会得到404错误。
我将在这里放置我的初始化TomCat日志,以及我的Controller、POM.xml和Main类。
谢谢如果你们需要更多信息告诉我。
- TomCat日志初始化 *
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jun 2 2022 19:08:46 UTC
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.64.0
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jre1.8.0_333
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_333-b02
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=\apache-tomcat-9.0.64\conf\logging.properties
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=\apache-tomcat-9.0.64\temp
07-Jul-2022 11:09:14.811 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.33] using APR version [1.7.0].
07-Jul-2022 11:09:14.811 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
07-Jul-2022 11:09:14.827 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
07-Jul-2022 11:09:14.827 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1o 3 May 2022]
07-Jul-2022 11:09:15.215 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
07-Jul-2022 11:09:15.265 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [710] milliseconds
07-Jul-2022 11:09:15.297 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
07-Jul-2022 11:09:15.297 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.64]
07-Jul-2022 11:09:15.328 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [C:\apache-tomcat-9.0.64\webapps\scim.war]
07-Jul-2022 11:09:19.655 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
07-Jul-2022 11:09:20.057 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [269] milliseconds.
07-Jul-2022 11:09:20.075 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [C:\apache-tomcat-9.0.64\webapps\scim.war] has finished in [4,747] ms
07-Jul-2022 11:09:20.075 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\docs]
07-Jul-2022 11:09:20.127 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\docs] has finished in [52] ms
07-Jul-2022 11:09:20.127 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\examples]
07-Jul-2022 11:09:20.684 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\examples] has finished in [557] ms
07-Jul-2022 11:09:20.684 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\host-manager]
07-Jul-2022 11:09:20.757 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\host-manager] has finished in [72] ms
07-Jul-2022 11:09:20.757 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\manager]
07-Jul-2022 11:09:20.794 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\manager] has finished in [37] ms
07-Jul-2022 11:09:20.794 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\ROOT]
07-Jul-2022 11:09:20.849 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\ROOT] has finished in [55] ms
07-Jul-2022 11:09:20.849 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
07-Jul-2022 11:09:20.866 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [5601] milliseconds
- 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ushin</groupId>
<artifactId>scim</artifactId>
<name>scim</name>
<description>scim</description>
<packaging>war</packaging>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<!--Spring-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!--MySQL-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
<build>
<finalName>scim</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Users\gbrasolin\.jdks\corretto-11.0.15\bin\javac.exe</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>scim</server>
<path>/scim</path>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
- 控制器 *
package com.ushin.scim.controllers;
import com.ushin.scim.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
@Controller
@RequestMapping(value = "/Users")
public class UserController {
UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody Map createUser(@RequestBody Map<String, Object> payload, HttpServletResponse response){
return userService.createUser(payload, response);
}
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody Map getUsers(@RequestParam Map<String, String> payload) throws IOException {
return userService.getUsers(payload);
}
@RequestMapping(value = "/{id}")
public @ResponseBody Map getSingleUser (@PathVariable String id, HttpServletResponse response){
return userService.getSingleUser(id, response);
}
@RequestMapping(method = RequestMethod.PUT, value = "/{id}")
public @ResponseBody Map updateUser(@RequestBody Map<String, Object> payload, @PathVariable String id){
return userService.updateUser(payload, id);
}
@RequestMapping(method = RequestMethod.PATCH, value = "/{id}")
public @ResponseBody Map disableUser (@RequestBody Map<String, Object> payload, @PathVariable String id){
return userService.disableUser(payload, id);
}
}
- 主类 *
package com.ushin.scim;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class ScimApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ScimApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
return builder.sources(ScimApplication.class);
}
}
1条答案
按热度按时间ej83mcc01#
我把JRE_HOME(运行的是java 8)的路径改成了JAVA_HOME的路径,这和Java 11是一样的。Tomcat运行的是Java 8,而我的项目运行的是Java 11。
日志:
Using JRE_HOME: "C:\Program Files\Java\jre1.8.0_333"
我的POM.xml:
<java.version>11</java.version>