Jak używać właściwości z pliku właściwości określonego w PropertyPlaceholderConfigurer w JSP
W moim kontekście aplikacji mam zdefiniowany Plik Właściwości:
<context:property-placeholder location="classpath:application.properties" />
Chcę uzyskać wartość właściwości zdefiniowanej w tym Pliku na stronie JSP. Czy jest na to sposób
${something.myProperty}?
6 answers
PropertyPlaceholderConfigurer
może analizować tylko symbole zastępcze w konfiguracji Spring (XML lub adnotacje). Bardzo często w zastosowaniach wiosennych używa się fasoli Properties
. Możesz uzyskać do niego dostęp z widoku w ten sposób (zakładając, że używasz 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>
Następnie w JSP możesz użyć ${properties.myProperty}
lub ${properties['my.property']}
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-13 09:42:07
Po wiosennej wersji 3.1 można użyć znacznika <spring:eval />
z SpEL w następujący sposób:
<spring:eval expression="@applicationProps['application.version']"
var="applicationVersion"/>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-29 12:52:40
Aby użyć z wieloma lokalizacjami na liście, które mogą nie być obecne, jak można to zrobić za pomocą 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>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-26 13:45:55
Aby użyć rekurencyjnego rozszerzenia właściwości zastępczych w widokach, potrzebujesz innego rozwiązania, spójrz na tę odpowiedź:
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:55:07
`<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
id="messageSource"
p:basenames="WEB-INF/i18n/site"
p:fallbackToSystemLocale="false"/>`
Teraz to jest Twój Plik Właściwości
`site.name=Cool Bananas`
I. 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>`
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-09 20:36:45
Wyświetli Ci tabele bieżącego schematu (który jesteś zalogowany):
select table_name from user_tables order by table_name;
To pokaże Ci tabele schematu, dla których masz co najmniej prawa wyboru:
select owner, table_name from all_tables where owner='<owner>' order by owner, table_name;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-20 07:00:25