私のアプリケーションコンテキストでは、プロパティファイルを定義しました。
<context:property-placeholder location="classpath:application.properties" />
JSPページのそのファイルで定義されているプロパティの値を取得したい。その方法でそれを行う方法はありますか
${something.myProperty}?
PropertyPlaceholderConfigurer
Spring構成(XMLまたはアノテーション)のプレースホルダーのみを解析できます。SpringアプリケーションではProperties
Beanを使用するのが非常に一般的です。この方法でビューからアクセスできます(使用していると仮定します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']}
。
Spring 3.1以降、次のようにSpEL<spring:eval />
でタグを使用できます。
<spring:eval expression="@applicationProps['application.version']"
var="applicationVersion"/>
コンテキストで実行できるように存在しない可能性のあるリスト内の複数の場所で使用するには: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>
ビューで再帰的なプロパティプレースホルダー展開を使用するには、別のソリューションが必要です。次の回答をご覧ください。
`<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>`
これにより、(ログインしている)現在のスキーマのテーブルが表示されます。
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;