私は次のプロジェクト構造を持っています
-src
-main
-java
-com
-test
Application.java
-controllers
MyController.java
-webapp
-WEB-INF
-jsp
main.jsp
これと似たようなことをしたいのですが、コントローラーに次のものがあります
@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が表示されます。Spring 4ではビューリゾルバーは必要ないと思っていましたが、必要な場合はどのように構成すればよいですか。
アップデート
次のようにapplication.propertiesを作成しました...
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
application.message: Hello Phil
しかし、それはまだ機能していません。
更新 2
提供されているSpringのサンプルも以下の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;
}
これも機能していないようです。