Comment utiliser la propriété à partir du fichier spécifié dans la propriété PropertyPlaceholderConfigurer en JSP

StackOverflow https://stackoverflow.com/questions/3933862

  •  30-09-2019
  •  | 
  •  

Question

Dans mon contexte d'application que je l'ai défini le fichier de propriétés:

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

Je veux obtenir la valeur de la propriété définie dans ce fichier à la page JSP. Est-il possible de le faire de la manière

${something.myProperty}?
Était-ce utile?

La solution

PropertyPlaceholderConfigurer ne peut analyser des espaces réservés dans la configuration Spring (XML ou annotations). Est très courant dans les applications Spring utilisent un grain de Properties. Vous pouvez y accéder à partir de votre point de vue de cette façon (en supposant que vous utilisez 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>

Ensuite, dans votre JSP, vous pouvez utiliser ${properties.myProperty} ou ${properties['my.property']}.

Autres conseils

`<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" 
  id="messageSource"
  p:basenames="WEB-INF/i18n/site"
  p:fallbackToSystemLocale="false"/>`

Maintenant, ceci est votre Fichier Propriétés

`site.name=Cool Bananas`

. Ici va JSP

`<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
  <head>
    <title><spring:message code="site.name"/></title>
  </head>
  <body>
  </body>
</html>`

Cela vous montrera les tables du schéma actuel (que vous êtes connecté):

select table_name from user_tables order by table_name;

Cela vous montrera les tables de schéma, pour lesquels vous avez des droits sélectionner au moins:

select owner, table_name from all_tables where owner='<owner>' order by owner, table_name;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top