Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在SpringJSP中显示.properties值_Java_Spring_Jsp_Javabeans_Spring Java Config - Fatal编程技术网

Java 在SpringJSP中显示.properties值

Java 在SpringJSP中显示.properties值,java,spring,jsp,javabeans,spring-java-config,Java,Spring,Jsp,Javabeans,Spring Java Config,我试图在每个jsp页面的页脚中显示我在Spring4中构建的应用程序的版本。我想从.properties文件中读取该值,并将其输出到footer.jsp,该文件将在每个页面上继承 它没有像我希望的那样工作,我很难调试它 问题:这是正确的方法吗?如果是这样,有什么建议我做错了什么 我试过: 上下文配置: @Bean(name=“applicationVersion”) 公共字符串applicationVersion(){ 返回environment.getRequiredProperty(“app

我试图在每个jsp页面的页脚中显示我在Spring4中构建的应用程序的版本。我想从.properties文件中读取该值,并将其输出到footer.jsp,该文件将在每个页面上继承

它没有像我希望的那样工作,我很难调试它

问题:这是正确的方法吗?如果是这样,有什么建议我做错了什么

我试过:

上下文配置:

@Bean(name=“applicationVersion”)
公共字符串applicationVersion(){
返回environment.getRequiredProperty(“application.version”);
}
@javaConfig

@Bean
公共视图解析程序jspViewResolver(){
InternalResourceViewResolver viewResolver=新的InternalResourceViewResolver();
setViewClass(JstlView.class);
viewResolver.SetExposeContextBeanSatAttribute(true);
setExposedContextBeanNames(“应用程序版本”);
返回视图解析器;
}
JSP:


我不确定你在看什么,只是一些我可以帮助你的指南:

在Java配置中设置属性文件

@Bean(name = "PropertiesFile")
public static PropertyPlaceholderConfigurer cmsProperties() {
    PropertyPlaceholderConfigurer placeholder = new PropertyPlaceholderConfigurer();
    ClassPathResource[] value = new ClassPathResource[] { new ClassPathResource("Put your properties location here") };
    placeholder.setLocations(value);
    return placeholder;
}
如果你想使用属性文件中的数据

只需使用
@Value

例如,在属性文件中,您有以下内容:

version=1.3
然后,要调用它,只需在控制器或bean中使用以下命令:

@Value("${version}") String version

我希望它能帮上忙

我不熟悉
Spring
,但是在将它发送到您的
JSP
之前,您是否尝试过在控制台上打印一些东西?以防万一。。。