I am trying to customize Spring boot using annotations. I have a class
@EnableWebMvc
@Configuration
@ComponentScan({
...
})
@EnableTransactionManagement
@EnableAutoConfiguration
@Import({ SecurityConfig.class })
public class AppConfig extends SpringBootServletInitializer {...}
which contains this prominent resolver that works great.
@Bean
public InternalResourceViewResolver internalViewResolver() {
InternalResourceViewResolver viewResolver
= new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/pages/");
viewResolver.setSuffix(".jsp");
viewResolver.setOrder(1);
return viewResolver;
}
But after receiving the application name of the JSP file, execute this error:
No mapping was found for the HTTP request with the URI [/WEB-INF/pages/MainPage.jsp] in the DispatcherServlet named "dispatcherServlet".
I found a solution for XML configuration:
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
But I use the configuration of annotations, so this soul is not suitable for me.
I tried to solve this problem by extending AbstractAnnotationConfigDispatcherServletInitializer
public class SpringMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { AppConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
. , AbstractAnnotationConfigDispatcherServletInitializer, , , , . . , ?
, : Mapping servlet: 'dispatcherServlet' to [/]
, , .
, . InternalResourceViewResolver application.properties :
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
: javax.servlet.ServletException: "MainPage" "dispatcherServlet"
, ?
UPDATE
.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>edu.springtest</groupId>
<artifactId>SpringTest</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.0.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
Main.java
@Controller
@Configuration
@ComponentScan
@EnableAutoConfiguration
@SpringBootApplication
public class Main {
@RequestMapping("/")
String home() {
return "hello";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Main.class, args);
}
}
application.properties
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
:

mvn spring -boot:
edu.test.Main: Main 2.365 ( JVM 5.476).
localhost: 8080, :
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Dec 20 11:25:29 EET 2014
There was an unexpected error (type=Not Found, status=404).
No message available
" ..." . localhost: 8080 .
?