SPR-7477 - Added lazy-init attribute to jee namespace
This commit is contained in:
parent
385d8e9482
commit
c7a350cde7
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.ejb.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import static org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.*;
|
||||
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
|
@ -31,6 +32,7 @@ import org.springframework.util.xml.DomUtils;
|
|||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
* @author Oliver Gierke
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract class AbstractJndiLocatingBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
@ -44,7 +46,8 @@ abstract class AbstractJndiLocatingBeanDefinitionParser extends AbstractSimpleBe
|
|||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return (super.isEligibleAttribute(attributeName) && !ENVIRONMENT_REF.equals(attributeName));
|
||||
return (super.isEligibleAttribute(attributeName) && !ENVIRONMENT_REF.equals(attributeName) && !LAZY_INIT_ATTRIBUTE
|
||||
.equals(attributeName));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,6 +64,10 @@ abstract class AbstractJndiLocatingBeanDefinitionParser extends AbstractSimpleBe
|
|||
definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, new RuntimeBeanReference(envRef));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String lazyInit = element.getAttribute(LAZY_INIT_ATTRIBUTE);
|
||||
if (StringUtils.hasText(lazyInit) && !DEFAULT_VALUE.equals(lazyInit)) {
|
||||
definitionBuilder.setLazyInit(TRUE_VALUE.equals(lazyInit));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,6 +205,19 @@
|
|||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="lazy-init" default="default" type="beans:defaultable-boolean">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether or not this bean is to be lazily initialized.
|
||||
If false, it will be instantiated on startup by bean factories
|
||||
that perform eager initialization of singletons. The default is
|
||||
"false".
|
||||
|
||||
Note: This attribute will not be inherited by child bean definitions.
|
||||
Hence, it needs to be specified per concrete bean definition.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.springframework.jndi.JndiObjectFactoryBean;
|
|||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class JeeNamespaceHandlerTests {
|
||||
|
||||
|
@ -129,6 +130,16 @@ public class JeeNamespaceHandlerTests {
|
|||
assertPropertyValue(beanDefinition, "cacheSessionBean", "true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyInitJndiLookup() throws Exception {
|
||||
BeanDefinition definition = this.beanFactory.getMergedBeanDefinition("lazyDataSource");
|
||||
assertTrue(definition.isLazyInit());
|
||||
definition = this.beanFactory.getMergedBeanDefinition("lazyLocalBean");
|
||||
assertTrue(definition.isLazyInit());
|
||||
definition = this.beanFactory.getMergedBeanDefinition("lazyRemoteBean");
|
||||
assertTrue(definition.isLazyInit());
|
||||
}
|
||||
|
||||
private void assertPropertyValue(BeanDefinition beanDefinition, String propertyName, Object expectedValue) {
|
||||
assertEquals("Property '" + propertyName + "' incorrect",
|
||||
expectedValue, beanDefinition.getPropertyValues().getPropertyValue(propertyName).getValue());
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:jee="http://www.springframework.org/schema/jee"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
|
||||
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
|
||||
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
|
@ -67,5 +67,12 @@
|
|||
cache-session-bean="true">
|
||||
<jee:environment>foo=bar</jee:environment>
|
||||
</jee:remote-slsb>
|
||||
|
||||
<!-- Lazy beans Tests-->
|
||||
<jee:jndi-lookup id="lazyDataSource" jndi-name="jdbc/MyDataSource" lazy-init="true" />
|
||||
<jee:local-slsb id="lazyLocalBean" jndi-name="ejb/MyLocalBean"
|
||||
business-interface="org.springframework.beans.ITestBean" lazy-init="true" />
|
||||
<jee:remote-slsb id="lazyRemoteBean" jndi-name="ejb/MyRemoteBean"
|
||||
business-interface="org.springframework.beans.ITestBean" lazy-init="true" />
|
||||
|
||||
</beans>
|
||||
|
|
Loading…
Reference in New Issue