SPR-7477 - Added lazy-init attribute to jee namespace

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4431 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Oliver Gierke 2011-06-03 08:51:56 +00:00
parent 976955f6ad
commit 67ffadd1f4
4 changed files with 43 additions and 5 deletions

View File

@ -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));
}
}
}

View File

@ -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>

View File

@ -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());

View File

@ -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>