복붙노트

[SPRING] JSP에서 PropertyPlaceholderConfigurer에 지정된 속성 파일의 속성을 사용하는 방법

SPRING

JSP에서 PropertyPlaceholderConfigurer에 지정된 속성 파일의 속성을 사용하는 방법

내 응용 프로그램 컨텍스트에서 속성 파일을 정의했습니다.

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

JSP 페이지에서 해당 파일에 정의 된 속성 값을 가져 오려고합니다. 방법으로 그렇게 할 수 있습니까?

${something.myProperty}?

해결법

  1. ==============================

    1.PropertyPlaceholderConfigurer는 스프링 설정 (XML 또는 주석)에서만 자리 표시자를 구문 분석 할 수 있습니다. Spring 애플리케이션에서 매우 일반적으로 사용되는 것은 Properties 빈을 사용한다. InternalResourceViewResolver를 사용한다고 가정하면 다음과 같이보기에서 액세스 할 수 있습니다.

    PropertyPlaceholderConfigurer는 스프링 설정 (XML 또는 주석)에서만 자리 표시자를 구문 분석 할 수 있습니다. Spring 애플리케이션에서 매우 일반적으로 사용되는 것은 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']}를 사용할 수 있습니다.

  2. ==============================

    2.Spring 3.1 이후에, 태그를 SpEL과 같이 사용할 수 있습니다 :

    Spring 3.1 이후에, 태그를 SpEL과 같이 사용할 수 있습니다 :

    <spring:eval expression="@applicationProps['application.version']" 
                 var="applicationVersion"/>
    
  3. ==============================

    3.컨텍스트 : property-placeholder bean으로 수행 할 수있는 것처럼 존재하지 않을 수도있는 목록의 여러 위치와 함께 사용하려면 다음을 수행하십시오.

    컨텍스트 : 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>
    
  4. ==============================

    4.보기에서 재귀 적 속성 자리 표시 자 확장을 사용하려면 다른 해결책이 필요합니다.이 대답을 살펴보십시오.

    보기에서 재귀 적 속성 자리 표시 자 확장을 사용하려면 다른 해결책이 필요합니다.이 대답을 살펴보십시오.

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

  5. ==============================

    5.

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

    이제 이것이 당신의 Properties 파일입니다.

    `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>`
    
  6. ==============================

    6.그러면 로그인 한 현재 스키마의 테이블이 표시됩니다.

    그러면 로그인 한 현재 스키마의 테이블이 표시됩니다.

    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;
    
  7. from https://stackoverflow.com/questions/3933862/how-to-use-property-from-property-file-specified-in-propertyplaceholderconfigure by cc-by-sa and MIT license