Java ApacheTomcat不通过IntelliJ工作,但在手动启动时工作
我正在尝试使用Spring和Tomcat测试简单的“hello”应用程序。我能够在localhost:8080上手动启动ApacheTomcat,并且我成功地访问了Apache站点,该站点显示其配置正确。但是,当我尝试通过IntelliJ启动我的应用程序时,我没有收到任何错误,在localhost:8080/sayHello上,我收到消息请求的资源[/sayHello]不可用 这是我的配置类:Java ApacheTomcat不通过IntelliJ工作,但在手动启动时工作,java,spring,spring-mvc,tomcat,Java,Spring,Spring Mvc,Tomcat,我正在尝试使用Spring和Tomcat测试简单的“hello”应用程序。我能够在localhost:8080上手动启动ApacheTomcat,并且我成功地访问了Apache站点,该站点显示其配置正确。但是,当我尝试通过IntelliJ启动我的应用程序时,我没有收到任何错误,在localhost:8080/sayHello上,我收到消息请求的资源[/sayHello]不可用 这是我的配置类: @Configuration @ComponentScan("app") publ
@Configuration
@ComponentScan("app")
public class Config extends AbstractAnnotationConfigDispatcherServletInitializer {
protected Class<?>[] getRootConfigClasses() {
return new Class[0];
}
protected Class<?>[] getServletConfigClasses() {
return new Class[0];
}
protected String[] getServletMappings() {
return new String[0];
}
}
以下是pom:
<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>org.example</groupId>
<artifactId>Spring</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
4.0.0
org.example
春天
1.0-快照
战争
1.6
1.6
org.springframework
SpringWebMVC
5.2.7.发布
javax.servlet
javax.servlet-api
4.0.1
假如
我希望我没有错过任何东西。如果是,请提醒我。这是我第一次接触Spring和Tomcat。web.xml文件中可能缺少映射。你能添加它的内容吗?我在我的项目中根本看不到这个文件。我读到它应该在/WEB-INF中,但我只有两个子文件夹:/classes和/lib。编辑:我还读到我可以手动生成它,但最好不要使用注释而不是xml。我相信即使使用注释,文件也应该在那里。可能web.xml文件中缺少映射。你能添加它的内容吗?我在我的项目中根本看不到这个文件。我读到它应该在/WEB-INF中,但我只有两个子文件夹:/classes和/lib。编辑:我还读到我可以手动生成它,但最好不要使用注释而不是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>org.example</groupId>
<artifactId>Spring</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>