使用注释弹簧4

时间:2015-11-20 14:54:47

标签: java spring jsp spring-annotations spring-4

我需要使用注释,而不使用xml文件。

< bean id="placeholderConfig"       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
        < property name="locations" >
            < list >
                < value >app.properties< / value >
            < / list >
        < / property >
< / bean >

我需要在我的jsp中调用我的属性值,如${test.name}(其中test.name在app.properties中配置)

现在我这样做

@PropertySource(value="app.properties", ignoreResourceNotFound=true)
...
@Bean(name="placeholderConfig")
    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer(){
        PropertySourcesPlaceholderConfigurer cfg = new PropertySourcesPlaceholderConfigurer();
        cfg.setLocation(new ClassPathResource("app.properties"));
        cfg.setIgnoreUnresolvablePlaceholders(true);
        return cfg;
    }

通过这种方式我可以访问whith

@Value("${test.name}")
    String name; //contain value of test.name configured in app.properties

但如果我在我的jsp中执行$ {test.name},则不会读取此内容。 让jsp读取我必须做的值(在我的java类中)

@Value("${test.name}")
    String name;
...
model.addObject("name", name);

有一种方法可以从我的jsp,whit ${test.name}代码直接访问我的媒体资源吗?

0 个答案:

没有答案
相关问题