在Java3.1.1中是否可以使用Spring注解来配置视图解析器?
我已经完成了使用Java的所有配置,但我仍然只能使用视图解析器。
代码
package com;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import com.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@ComponentScan("com")
public class AppConfig
{
{
//Other bean declarations
}
@Bean
public UrlBasedViewResolver urlBasedViewResolver()
{
UrlBasedViewResolver res = new InternalResourceViewResolver();
res.setViewClass(JstlView.class);
res.setPrefix("/WEB-INF/");
res.setSuffix(".jsp");
return res;
}
}
我使用了这段代码并运行了应用程序,但它没有返回适当的视图。但是,如果我在app-servlet.xml
文件中配置一个视图解析器,它就能正常工作。
https://stackoverflow.com/questions/14426947
复制相似问题