![](/img/trans.png)
[英]JSF Spring MVC application cannot load Application context.xml
[英]Load webserver context.xml using Spring
對Spring來說還很陌生,所以我對此有些麻煩。 我正在嘗試通過LDAP使用LDAP安全性。 我可以使用在webapp本身內部創建的屬性文件。 但是我想做的是加載並讀取服務器的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。 它是否必須是服務器上的絕對路徑?
謝謝克里斯
因此,我建議的第一件事是使用Spring Security 。 它已經內置了LDAP支持。
但找不到context.xml
通常,這(直接讀取context.xml
)不是您應該采取的方法。 而是在context.xml
定義一些屬性和/或JNDI資源,然后在spring配置中使用它們。
例如:
<?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="test@example.com"
mail.smtp.host="mail.example.com"
mail.smtp.from="test@example.com"/>
<Parameter name="simpleValue" value="any" override="false" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.