2011-10-17 3 views
1

Springにはまったく新しいので、これにいくつか問題があります。私は春にLDAPセキュリティを使用しようとしています。私はwebapp内で作成したプロパティファイルを使用できます。しかし、私がしたいのは、サーバーのcontext.xmlファイルをロードして読み込むことです(このアプリケーションや他のアプリケーションに必要なすべての値があります)。Springを使用してwebserver context.xmlをロードする

これは私が持っているものです。

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="ignoreUnresolvablePlaceholders" value="true"/> 
    </bean> 
    <bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer"> 
     <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/> 
     <property name="searchContextAttributes" value="true"/> 
     <property name="contextOverride" value="true"/> 
     <property name="ignoreResourceNotFound" value="true"/> 
     <property name="locations"> 
      <list> 

       <value>/WEB-INF/properties/dataUploadProperties.properties</value> 
       <value>/WEB-INF/properties/globalProperties.properties</value> 
       <value>context.xml</value> 

      </list> 
     </property> 
    </bean> 

私は2つのプロパティファイルをロードし、読むことができるんだけど、context.xmlには見つかりませんでした。それはサーバー上の絶対パスである必要がありますか?

おかげ クリス

答えて

0

は、だから私は推薦する最初の事はSpring Securityを使用することです。それはすでにLDAPサポートを構築しています。


but the context.xml is not found

通常、これは(直接context.xmlを読んで)あなたは行くべき道ではありません。 代わりに、いくつかのプロパティとJNDIリソースをcontext.xmlに定義し、それらをスプリング構成で使用します。例えば

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:jee="http://www.springframework.org/schema/jee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
       http://www.springframework.org/schema/jee 
       http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"> 

    <!-- access via jndi --> 
    <jee:jndi-lookup id="jndiEmailSession" 
     jndi-name="java:comp/env/email/session/myEmailSession" /> 

    <!-- direct access for properties required the SERVLET contect property 
     place older configurer, then it works like properties from normal 
     property files --> 
    <bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">  <property name="locations" value="classpath*:META-INF/spring/*.properties" /> </bean> 

    <bean class=Demo> 
     <property name="someString" value="${simpleValue}" /> 
    </bean> 
</beans> 

のcontext.xml:私は春のセキュリティを使用しています

<Resource name="email/session/myEmailSession" 
      type="javax.mail.Session" 
      auth="Container"       
    password="secret" 
    mail.debug="false" 
    mail.transport.protocol="smtp" 
    mail.smtp.auth="true" 
    mail.smtp.user="[email protected]" 
    mail.smtp.host="mail.example.com" 
    mail.smtp.from="[email protected]"/> 

<Parameter name="simpleValue" value="any" override="false" /> 
+0

。私は各サーバーは別のURLを持っているので、サーバーcontext.xmlファイルからLDAPのURLを取得しようとしています。ありがとう –

+0

@Chris Mattmiller:この場合は、context.xmlのLDAP接続をjndi ressourceとして定義する必要があります – Ralph

+0

jndiリソースとして設定すると、このエラーが表示されます。1行目、1列目の字句エラー: "$"(36)、後: "" –

関連する問題