我可以轻松地在 XML 中进行配置,但在 @Configuration 中却不行。
特性
spring.view.class=org.springframework.web.servlet.view.JstlView
spring.view.prefix=/WEB-INF/jsp/
spring.view.suffix=.jsp
代码
@Bean
public UrlBasedViewResolver viewResolver() throws ClassNotFoundException {
//ViewResolver Setting
Class viewResolverClass = env.getPropertyAsClass("spring.view.class", Class.class);
String viewResolverPrefix = env.getProperty("spring.view.prefix");
String viewResolverSuffix = env.getProperty("spring.view.suffix");
UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
viewResolver.setViewClass(viewResolverClass);
viewResolver.setPrefix(viewResolverPrefix);
viewResolver.setSuffix(viewResolverSuffix);
return viewResolver;
}
错误
throws java.lang.ClassNotFoundException] threw exception; nested exception is java.lang.IllegalArgumentException: Cannot convert value [org.springframework.web.servlet.view.JstlView] from source type [String] to target type [Class]
提前致谢。