JSPのPropertyPlaceHolderConfigurerで指定されたプロパティファイルからプロパティの使用方法
質問
アプリケーションのコンテキストでは、プロパティファイルを定義しました。
<context:property-placeholder location="classpath:application.properties" />
JSPページのそのファイルで定義されているプロパティの価値を取得したいと思います。邪魔になる方法はありますか
${something.myProperty}?
解決
PropertyPlaceholderConfigurer
Spring構成(XMLまたは注釈)でのみプレースホルダーのみを解析できます。春のアプリケーションでは非常に一般的です Properties
豆。この方法であなたの見解からアクセスできます(使用していると仮定して 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']}
.
他のヒント
春3.1の後、使用できます <spring:eval />
でタグ スペル このような:
<spring:eval expression="@applicationProps['application.version']"
var="applicationVersion"/>
リスト内の複数の場所で使用するには、コンテキストで実行できるように存在しない可能性があります。プロパティプレイスホルダー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;
所属していません StackOverflow