How to use property from property file specified in PropertyPlaceholderConfigurer in JSP

无人久伴 提交于 2019-11-27 19:29:35

PropertyPlaceholderConfigurer can only parse placeholders in Spring configuration (XML or annotations). Is very common in Spring applications use a Properties bean. You can access it from your view this way (assuming you are using InternalResourceViewResolver):

<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
        <list><value>classpath:config.properties</value></list>
    </property>
</bean>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
    <property name="exposedContextBeanNames">
        <list><value>properties</value></list>
    </property>
</bean>

Then, in your JSP, you can use ${properties.myProperty} or ${properties['my.property']}.

After Spring 3.1, you can use <spring:eval /> tag with SpEL like this:

<spring:eval expression="@applicationProps['application.version']" 
             var="applicationVersion"/>

To use with multiple locations in a list which might not be present as can be done with the context:property-placeholder bean:

<beans:bean id="appProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <beans:property name="ignoreResourceNotFound" value="true" />
    <beans:property name="locations">
        <beans:list>
            <beans:value>classpath:application.properties</beans:value>
            <beans:value>classpath:environment.properties</beans:value>
            <beans:value>classpath:environment-${env}.properties</beans:value>
        </beans:list>
    </beans:property>
</beans:bean>
anttix

To use recursive property placeholder expansion in views, you need a different solution, take a look at this answer:

https://stackoverflow.com/a/10200249/770303

`<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" 
  id="messageSource"
  p:basenames="WEB-INF/i18n/site"
  p:fallbackToSystemLocale="false"/>`

Now this is your Properties File

`site.name=Cool Bananas`

And. Here goes your JSP

`<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
  <head>
    <title><spring:message code="site.name"/></title>
  </head>
  <body>
  </body>
</html>`
user3331318

This will show you the tables of the current schema (which you are logged in):

select table_name from user_tables order by table_name;

This will show you the tables of schema , for which you have select rights at least:

select owner, table_name from all_tables where owner='<owner>' order by owner, table_name;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!