我有以下项目结构春季启动4层不渲染的JSP抛出404
-src
-main
-java
-com
-test
Application.java
-controllers
MyController.java
-webapp
-WEB-INF
-jsp
main.jsp
我想要做类似this的东西,但在我的控制,我有以下
@Controller
@RequestMapping("/my/**")
public class MyController {
@RequestMapping("/home")
public String loadHomePage(Model m) {
m.addAttribute("name", "CodeTutr");
System.out.println("Test the view controller");
return "main";
}
}
,当我去http://localhost:8080/my/home
我得到了日志消息和一个404。我在春季4想到我不需要视图解析器,但如果我这样做,我该如何配置它。
更新
我创建了一个application.properties有以下...
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
application.message: Hello Phil
但它仍然没有工作。
更新2
所提供的样品春天似乎也与以下的build.gradle以同样的方式失败....
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.4.BUILD-SNAPSHOT")
}
}
apply plugin: 'war'
apply plugin: 'spring-boot'
apply plugin: 'groovy'
war { baseName='itext' }
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url "http://repo.spring.io/libs-release" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-websocket")
compile("org.springframework:spring-messaging")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile 'org.codehaus.groovy:groovy-all:2.2.0'
compile 'com.lowagie:itext:4.2.1'
compile 'com.google.code.gson:gson:2.2.4'
}
更新
我也试图明确...
@Bean
public ViewResolver getViewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
这似乎也不起作用。
这是不需要在春季4看到更新后的帖子与链接。每个原始问题也不使用XML。 – Jackie
不在Spring 4 w/boot中查看提供的链接和示例 – Jackie
实际上,它在我的build.gradle中一定是错误的,所以我会补充一点。春天,XML仍然是一种非常古老且不赞成使用的映射bean的方式。带有注解与XML的更新版本将反转我的投票。 – Jackie