【发布时间】:2019-01-11 07:16:50
【问题描述】:
我在 src/main 中手动创建 webapp/WEB-INF/views 文件夹,还添加了 2 个依赖项,例如 org.apache.tomcat.embed 和 javax.servlet 但它仍然抛出 404 当我在Controller的调用地址
控制器。
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HolidayController {
@GetMapping("/test11")
public String getData()
{
System.out.println("in the test contoller");
return "demoJsp";
}
}
Spring Boot 配置文件。
package com.chml.Chml_Admin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@EntityScan("com.chml")
@EnableJpaRepositories("com.chml")
@ComponentScan("com.chml")
public class ChmlAdminApplication {
public static void main(String[] args) {
SpringApplication.run(ChmlAdminApplication.class, args);
}
}
application.properties.
#==== connect to mysql ======#
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/chml_admin
spring.datasource.username=root spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
#==== Internal View Resolver ======#
spring.mvc.view.prefix=/WEB-INF/jsps/
spring.mvc.view.suffix=.jsp
JSP。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Demo</title>
</head>
<body>
<h3>This is jsp content</h3>
</body>
</html>
pom.xml.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<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-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
在这里我添加了我的项目结构
我尝试了各种方法,但没有得到任何解决方案, 如果我哪里出错了,请告诉我。
【问题讨论】:
-
添加你的项目结构截图
-
@lucumt 我刚刚添加了我的项目结构截图
-
我仍然没有任何正确的答案可以解决我的问题
标签: java spring-boot jsp