From 695559879e5bd7936cc60fba937889b49c9c2f8e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 20 Nov 2023 21:01:36 +0100 Subject: [PATCH] Restore outdated local/remote-slsb attributes for declaration compatibility Legacy EJB attributes are ignored since 6.0 due to being bound to a plain JndiObjectFactoryBean - but can still be declared now, e.g. when validating against the common versions of spring-jee.xsd out there. Closes gh-31627 --- ...lStatelessSessionBeanDefinitionParser.java | 11 ++- ...eStatelessSessionBeanDefinitionParser.java | 11 ++- .../springframework/ejb/config/spring-jee.xsd | 81 ++++++++++++++++++- .../ejb/config/JeeNamespaceHandlerTests.java | 36 ++++++++- .../ejb/config/jeeNamespaceHandlerTests.xml | 37 +++++++-- 5 files changed, 163 insertions(+), 13 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/ejb/config/LocalStatelessSessionBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/ejb/config/LocalStatelessSessionBeanDefinitionParser.java index 035fad6581f..14f6f88b10a 100644 --- a/spring-context/src/main/java/org/springframework/ejb/config/LocalStatelessSessionBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/ejb/config/LocalStatelessSessionBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,13 @@ package org.springframework.ejb.config; import org.w3c.dom.Element; +import org.springframework.beans.BeanUtils; import org.springframework.jndi.JndiObjectFactoryBean; /** * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} * implementation for parsing '{@code local-slsb}' tags and - * creating plain {@link JndiObjectFactoryBean} definitions. + * creating plain {@link JndiObjectFactoryBean} definitions on 6.0. * * @author Rob Harrop * @author Juergen Hoeller @@ -36,4 +37,10 @@ class LocalStatelessSessionBeanDefinitionParser extends AbstractJndiLocatingBean return JndiObjectFactoryBean.class; } + @Override + protected boolean isEligibleAttribute(String attributeName) { + return (super.isEligibleAttribute(attributeName) && + BeanUtils.getPropertyDescriptor(JndiObjectFactoryBean.class, extractPropertyName(attributeName)) != null); + } + } diff --git a/spring-context/src/main/java/org/springframework/ejb/config/RemoteStatelessSessionBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/ejb/config/RemoteStatelessSessionBeanDefinitionParser.java index a88c5f64618..9768e0dfc33 100644 --- a/spring-context/src/main/java/org/springframework/ejb/config/RemoteStatelessSessionBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/ejb/config/RemoteStatelessSessionBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,13 @@ package org.springframework.ejb.config; import org.w3c.dom.Element; +import org.springframework.beans.BeanUtils; import org.springframework.jndi.JndiObjectFactoryBean; /** * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} * implementation for parsing '{@code remote-slsb}' tags and - * creating plain {@link JndiObjectFactoryBean} definitions. + * creating plain {@link JndiObjectFactoryBean} definitions as of 6.0. * * @author Rob Harrop * @author Juergen Hoeller @@ -36,4 +37,10 @@ class RemoteStatelessSessionBeanDefinitionParser extends AbstractJndiLocatingBea return JndiObjectFactoryBean.class; } + @Override + protected boolean isEligibleAttribute(String attributeName) { + return (super.isEligibleAttribute(attributeName) && + BeanUtils.getPropertyDescriptor(JndiObjectFactoryBean.class, extractPropertyName(attributeName)) != null); + } + } diff --git a/spring-context/src/main/resources/org/springframework/ejb/config/spring-jee.xsd b/spring-context/src/main/resources/org/springframework/ejb/config/spring-jee.xsd index 283e803db81..97e05f62415 100644 --- a/spring-context/src/main/resources/org/springframework/ejb/config/spring-jee.xsd +++ b/spring-context/src/main/resources/org/springframework/ejb/config/spring-jee.xsd @@ -95,7 +95,7 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - + + @@ -183,6 +224,40 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-context/src/test/java/org/springframework/ejb/config/JeeNamespaceHandlerTests.java b/spring-context/src/test/java/org/springframework/ejb/config/JeeNamespaceHandlerTests.java index 65292d30573..862484d7d8f 100644 --- a/spring-context/src/test/java/org/springframework/ejb/config/JeeNamespaceHandlerTests.java +++ b/spring-context/src/test/java/org/springframework/ejb/config/JeeNamespaceHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,12 @@ package org.springframework.ejb.config; +import javax.naming.NoInitialContextException; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.RuntimeBeanReference; @@ -29,6 +32,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.jndi.JndiObjectFactoryBean; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Rob Harrop @@ -93,6 +97,10 @@ public class JeeNamespaceHandlerTests { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simpleLocalEjb"); assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName()); assertPropertyValue(beanDefinition, "jndiName", "ejb/MyLocalBean"); + + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> this.beanFactory.getBean("simpleLocalEjb")) + .withCauseInstanceOf(NoInitialContextException.class); } @Test @@ -100,6 +108,32 @@ public class JeeNamespaceHandlerTests { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simpleRemoteEjb"); assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName()); assertPropertyValue(beanDefinition, "jndiName", "ejb/MyRemoteBean"); + + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> this.beanFactory.getBean("simpleRemoteEjb")) + .withCauseInstanceOf(NoInitialContextException.class); + } + + @Test + public void testComplexLocalSlsb() { + BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complexLocalEjb"); + assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName()); + assertPropertyValue(beanDefinition, "jndiName", "ejb/MyLocalBean"); + + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> this.beanFactory.getBean("complexLocalEjb")) + .withCauseInstanceOf(NoInitialContextException.class); + } + + @Test + public void testComplexRemoteSlsb() { + BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complexRemoteEjb"); + assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName()); + assertPropertyValue(beanDefinition, "jndiName", "ejb/MyRemoteBean"); + + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> this.beanFactory.getBean("complexRemoteEjb")) + .withCauseInstanceOf(NoInitialContextException.class); } @Test diff --git a/spring-context/src/test/resources/org/springframework/ejb/config/jeeNamespaceHandlerTests.xml b/spring-context/src/test/resources/org/springframework/ejb/config/jeeNamespaceHandlerTests.xml index e8a47157a87..dd8f402278e 100644 --- a/spring-context/src/test/resources/org/springframework/ejb/config/jeeNamespaceHandlerTests.xml +++ b/spring-context/src/test/resources/org/springframework/ejb/config/jeeNamespaceHandlerTests.xml @@ -40,14 +40,41 @@ - + + + + foo=bar + - + - + + foo=bar + + + - - + + + +