首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用Java注解的ViewResolver

使用Java注解的ViewResolver
EN

Stack Overflow用户
提问于 2013-01-21 01:05:58
回答 3查看 31.7K关注 0票数 22

在Java3.1.1中是否可以使用Spring注解来配置视图解析器?

我已经完成了使用Java的所有配置,但我仍然只能使用视图解析器

代码

代码语言:javascript
复制
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文件中配置一个视图解析器,它就能正常工作。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14426947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档