Last active
September 3, 2015 10:01
-
-
Save gary-liguoliang/9403188 to your computer and use it in GitHub Desktop.
Using JNDI in Spring - JNDI DataSource / Environment - using a <jee:jndi-lookup string inside an instance of PropertyPlaceholderConfigurer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- by https://gist.github.com/prule/5523826 --> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:context="http://www.springframework.org/schema/context" | |
xmlns:jee="http://www.springframework.org/schema/jee" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd | |
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd"> | |
<!-- see https://gist.github.com/prule/5523793 for an example tomcat configuration exposing these JNDI resources --> | |
<context:property-placeholder order="1" ignore-unresolvable="true" system-properties-mode="OVERRIDE"/> | |
<bean id="envConfig" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"> | |
<!-- load properties bundled with the application --> | |
<property name="locations"> | |
<list> | |
<value>classpath:app.properties</value> | |
</list> | |
</property> | |
<!-- add JNDI based properties exposed by the container --> | |
<property name="properties"> | |
<bean class="java.util.Properties"> | |
<constructor-arg> | |
<map> | |
<entry key="ldap.host"> | |
<jee:jndi-lookup jndi-name="java:comp/env/ldap/host"/> | |
</entry> | |
</map> | |
</constructor-arg> | |
</bean> | |
</property> | |
</bean> | |
<!-- use the String exposed by JNDI --> | |
<bean id="contextSource" | |
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"> | |
<constructor-arg value="ldap://${ldap.host}/ou=users,dc=javathinking,dc=com"/> | |
<property name="userDn" value="uid=admin,ou=system"/> | |
<property name="password" value="secret"/> | |
</bean> | |
<!-- use the DataSource exposed by JNDI --> | |
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> | |
<property name="jndiName" value="java:comp/env/jdbc/mydb"/> | |
</bean> | |
<!-- use the mail Session exposed by JNDI --> | |
<bean id="mailSession" class="org.springframework.jndi.JndiObjectFactoryBean"> | |
<property name="jndiName" value="java:comp/env/mail/session"/> | |
</bean> | |
</beans> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error: The prefix "jee" for element "jee:jndi-lookup" is not bound.
Make sure the name space "jee' is there:
xmlns:jee="http://www.springframework.org/schema/jee"