Harmonize JNDI lookups to enable resourceRef
This commit makes sure that JMS and Mail JNDI lookups behave the same way as DataSource JNDI lookups by enabling the "resourceRef" flag. This will make sure to add "java:comp/env" to the lookup if the JNDI name doesn't already contain it. If that name does not exist, a second attempt to the original name will be issued automatically. Closes gh-12803
This commit is contained in:
@@ -93,7 +93,16 @@ public class JndiConnectionFactoryAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void jndiNamePropertySet() {
|
||||
ConnectionFactory connectionFactory = configureConnectionFactory("myCF");
|
||||
ConnectionFactory connectionFactory = configureConnectionFactory(
|
||||
"java:comp/env/myCF");
|
||||
this.contextRunner.withPropertyValues("spring.jms.jndi-name=java:comp/env/myCF")
|
||||
.run(assertConnectionFactory(connectionFactory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jndiNamePropertySetWithResourceRef() {
|
||||
ConnectionFactory connectionFactory = configureConnectionFactory(
|
||||
"java:comp/env/myCF");
|
||||
this.contextRunner.withPropertyValues("spring.jms.jndi-name=myCF")
|
||||
.run(assertConnectionFactory(connectionFactory));
|
||||
}
|
||||
|
||||
@@ -150,8 +150,18 @@ public class MailSenderAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void jndiSessionAvailable() {
|
||||
Session session = configureJndiSession("foo");
|
||||
this.contextRunner.withPropertyValues("spring.mail.jndi-name:foo")
|
||||
Session session = configureJndiSession("java:comp/env/foo");
|
||||
testJndiSessionLookup(session, "java:comp/env/foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jndiSessionAvailableWithResourceRef() {
|
||||
Session session = configureJndiSession("java:comp/env/foo");
|
||||
testJndiSessionLookup(session, "foo");
|
||||
}
|
||||
|
||||
private void testJndiSessionLookup(Session session, String jndiName) {
|
||||
this.contextRunner.withPropertyValues("spring.mail.jndi-name:" + jndiName)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(Session.class);
|
||||
Session sessionBean = context.getBean(Session.class);
|
||||
|
||||
Reference in New Issue
Block a user