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

后端 未结 6 1719
渐次进展
渐次进展 2020-12-05 05:21

In my application context I have defined properties file:


相关标签:
6条回答
  • 2020-12-05 05:58
    `<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>`
    
    0 讨论(0)
  • 2020-12-05 06:03

    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']}.

    0 讨论(0)
  • 2020-12-05 06:04

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

    <spring:eval expression="@applicationProps['application.version']" 
                 var="applicationVersion"/>
    
    0 讨论(0)
  • 2020-12-05 06:13

    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>
    
    0 讨论(0)
  • 2020-12-05 06:19

    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

    0 讨论(0)
  • 2020-12-05 06:20

    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;
    
    0 讨论(0)
提交回复
热议问题