0
我可以在XML中輕鬆配置,但不能在@Configuration中配置。如何將屬性文件中的spring 3.1 classNameString轉換爲類?
屬性
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]
在此先感謝。