15

私のアプリケーションコンテキストでは、プロパティファイルを定義しました。

<context:property-placeholder  location="classpath:application.properties" />

JSPページのそのファイルで定義されているプロパティの値を取得したい。その方法でそれを行う方法はありますか

${something.myProperty}?
4

6 に答える 6

38

PropertyPlaceholderConfigurerSpring構成(XMLまたはアノテーション)のプレースホルダーのみを解析できます。SpringアプリケーションではPropertiesBeanを使用するのが非常に一般的です。この方法でビューからアクセスできます(使用していると仮定します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>

次に、JSPで${properties.myProperty}またはを使用できます${properties['my.property']}

于 2010-10-14T14:07:14.220 に答える
6

Spring 3.1以降、次のようにSpEL<spring:eval />でタグを使用できます。

<spring:eval expression="@applicationProps['application.version']" 
             var="applicationVersion"/>
于 2013-08-29T12:52:40.527 に答える
0

コンテキストで実行できるように存在しない可能性のあるリスト内の複数の場所で使用するには: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>
于 2012-01-26T12:47:00.540 に答える
0

ビューで再帰的なプロパティプレースホルダー展開を使用するには、別のソリューションが必要です。次の回答をご覧ください。

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

于 2012-04-17T23:30:40.597 に答える
0
`<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" 
  id="messageSource"
  p:basenames="WEB-INF/i18n/site"
  p:fallbackToSystemLocale="false"/>`

これがプロパティファイルです

`site.name=Cool Bananas`

と。これがあなたのJSPです

`<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
  <head>
    <title><spring:message code="site.name"/></title>
  </head>
  <body>
  </body>
</html>`
于 2015-04-09T20:36:45.090 に答える
-4

これにより、(ログインしている)現在のスキーマのテーブルが表示されます。

select table_name from user_tables order by table_name;

これにより、少なくとも次の選択権限を持つスキーマのテーブルが表示されます。

select owner, table_name from all_tables where owner='<owner>' order by owner, table_name;
于 2014-02-20T06:37:03.400 に答える