【发布时间】:2014-10-04 07:05:39
【问题描述】:
我是 Spring 新手,我想将一些 URL 映射到 JSP 页面。我现在正在尝试这个 2 小时,但我无法让它工作。我确信这很简单,但我是 Spring 新手。我正在使用 Spring Boot。
(是的,我找到了How can I map my Spring URL to a JSP file in /WEB-INF/views? 之类的主题,但我认为我做的一切都是正确的......)
这是我的控制器。如果我在那里放一个断点,它就会被调用。因此,我认为 ViewResolver 有问题...
@Controller
@RequestMapping("customers")
public class WebController {
@RequestMapping(method=RequestMethod.GET)
public String customers(Locale locale, Model model) {
return "customers";
}
}
这是我的 WebSecurityConfigurerAdapter(我正在使用 Spring Security):
@Configuration
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//Some other methods, not relevant for this
@Bean
public InternalResourceViewResolver getViewResolver(){
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
我的 JSP 文件放在 WEB-INF/views/customers.jsp 中。 当我调用 localhost:8080/customers/ 我得到(这是唯一的错误。服务器日志中没有其他人......):
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Aug 11 14:18:47 CEST 2014
There was an unexpected error (type=Not Found, status=404).
【问题讨论】:
-
您的问题缺少一些细节:您的应用程序是否使用根上下文(或者您是否使用 spring-boot)?服务器日志中是否还有其他错误(我希望有...)?
-
我正在使用 Spring Boot。服务器日志中没有其他错误:-(
-
看来 spring
dispatcher-servlet没有启动。你在配置类上有@EnableWebMvc注释吗?
标签: spring spring-mvc spring-boot