我有一个工作启动MVC应用程序,我需要添加jsp视图。
我添加了所有必需的罐子
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
</dependency>
我的视图配置在application.yml
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
将我的jsp添加到src / main / webapp / WEB-INF
我的控制器
@Controller
public class PreAuthController {
@RequestMapping( value="/" , method = RequestMethod.GET )
public String index(){
return "dashboard";
}
@RequestMapping( value="/dashboard" , method = RequestMethod.GET )
public String dashboard(){
return "dashboard";
}
@RequestMapping( value="/login" , method = RequestMethod.GET )
public String login(){
return "login";
}
}
日志显示正确的docroot
文档根目录:/ Users / myhome / workspace / wi-preauth / wi-preauth-ui / src / main / webapp
当我尝试点击http://localhost:8080/
时我一直收到此错误
Could not resolve view with name 'login' in servlet with name
'dispatcherServlet'
我已经尝试过从论坛上提出的其他问题到无济于事的所有内容。
非常感谢任何帮助。
答案 0 :(得分:1)
我发现了我的问题。我有一个扩展WebMvcConfigurationSupport的配置类。这反过来会禁用WebMvcAutoConfiguration。 所以我不得不添加自己的
@Table(name = "tableName", schema = "databaseName")
在我的配置中。
答案 1 :(得分:0)
创建ApplicationContext java配置类。
ResourceHandlerRegistry
个位置有助于在JSP中注册加载静态文件(如css,图像,字体和js文件)的路径。
@Configuration
@EnableWebMvc
@ComponentScan
public class ApplicationContext extends WebMvcConfigurerAdapter
{
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/view/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
registry.viewResolver(resolver);
}
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/" };
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
if (!registry.hasMappingForPattern("/**")) {
registry.addResourceHandler("/**").addResourceLocations(
CLASSPATH_RESOURCE_LOCATIONS);
}
}
}