【发布时间】:2021-03-30 18:02:32
【问题描述】:
我在video 中做了所有事情:
但是当我输入:http://localhost:8080/spring-sample-1.0-SNAPSHOT/hello
出现此错误:
HTTP Status 404 – Not Found
Type Status Report
Message The requested resource [/spring-sample-1.0-SNAPSHOT/hello] 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.
我唯一改变的是:tomcat/bin/setclasspath.bat,我在那里添加了一行:
set JRE_HOME=C:\Program Files\Java\jre1.8.0_271
因为没有那个服务器不会启动
好吧,所以我的应用程序真的很简单,我在 java 15 中创建了 mvn 项目,然后是两个类:
配置:
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@Configuration
@ComponentScan({"app"})
@EnableWebMvc
public class Config extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[0];
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[0];
}
@Override
protected String[] getServletMappings() {
return new String[0];
}
}
你好:
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Hello {
@GetMapping("/hello")
public String get(){
return "Bycza zagroda!";
}
}
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>pl.bykowski</groupId>
<artifactId>spring-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
然后我把所有东西都打包到了war文件中,并在这里添加到tomcat管理器中:要部署的WAR文件
之后我点击了tomcat模块中的/spring-sample-1.0-SNAPSHOT
然后在最后输入你好
有什么想法吗? :/
【问题讨论】:
-
您提供的视频不是英文的。此外,您不应期望我们观看 19 分钟的视频来了解您作为代码所做的工作。所以,请提供足够的代码来帮助我们理解您的代码和问题,以便我们提供帮助
-
@UsemeAlehosaini 对不起,现在我修好了
标签: java spring tomcat intellij-idea servlets