spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
55.29k stars 37.62k forks source link

JndiObjectFactoryBean really needs as lookupOnStartup property [SPR-463] #5192

Closed spring-projects-issues closed 19 years ago

spring-projects-issues commented 19 years ago

Colin Sampaleanu opened SPR-463 and commented

JndiObjectFactoryBean really needs as lookupOnStartup property...

If somebody is not happy with the default JndiObjectFactoryBean behaviour of looking up the object on startup (looking up EJB homes is one of the prime candidates, as they are often not available yet when the webapp is already going), then this:

<bean id="simpleBeanHome" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName"><value>SimpleWithCmtAndNoSpringTx</value></property>
</bean>

becomes

\ \ \ \\SimpleWithCmtAndNoSpringTx\\ \\false\\ \ \ \ \org.springframework.autobuilds.ejbtest.simple.ejb.SimpleHomeRemote\ \ \ That's way too much work, in my opinion...


Affects: 1.1.2

spring-projects-issues commented 19 years ago

Juergen Hoeller commented

Good point. However, we should discuss whether to bake this into the standard JndiObjectFactoryBean: It currently doesn't have any AOP dependencies, and it should continue to work without spring-aop.jar in the class path. On the other hand, it would be nice to have those options on JndiObjectFactoryBean itself.

As a possible solution, we could move ProxyFactory/JndiObjectTargetSource usage into an inner class within JndiObjectFactoryBean, just called when actually needing a proxy (i.e. "lookupOnStartup"=true or "cache"=false). This would be similar to ProxyFactory itself handles CGLIB.

Juergen

spring-projects-issues commented 19 years ago

Colin Sampaleanu commented

I don't know why there really needs to be any dependency on the AOP package. Who says JndiObjectTargetSource really has to be used for this?

The lookupOnStartup option can be handled with code directly in JndiObjectFactoryBean. It's probably no more work to do that there, than to use JndiObjectTargetSource internally, and then you don't have to worry about specifying the interfaces either (right now you need to specify an interface unless you want to use a cglib proxy).

As for the cache option, is that even relevant? Right now JndiObjectFactoryBean is always a singleton, returning the same value. I suppose that it could allow a prototype mode, in which case it would always lookup the value again.

Then if people want a real proxy, they can still use the targetsource method with the proxy factory...

spring-projects-issues commented 19 years ago

Juergen Hoeller commented

Reworked JndiObjectFactoryBean accordingly. Use of AOP is appropriate in the case of lazy lookup or not caching, as we need to generate proxy. Should just be avoided in the default case.

Juergen

spring-projects-issues commented 19 years ago

Colin Sampaleanu commented

Hmm, sorry, I didn't think about the lifecycle implications. Of course it does need the proxy for lazy-lookup, as the factory is a singleton and will be pre-instantiated; that's the whole point.

spring-projects-issues commented 19 years ago

Juergen Hoeller commented

Colin, it would be great if you could give these new JndiObjectFactoryBean options a try, in particular with EJB homes. I've currently just tested them in unit tests; I'll try them with JMS (the original reason I developed JndiObjectTargetSource for).

Juergen

spring-projects-issues commented 19 years ago

Colin Sampaleanu commented

I'm ahead of you. I actually brought this up in the context of writing material for the book, so as of a few hours ago I had already pulled down your changes and used the new code to access an EJB Home (well, delayed lookup anyways, caching I didn't try) for examples for the book.

I'll slip in some tests into the ejbtest sample itself, pretty soon.

spring-projects-issues commented 19 years ago

Juergen Hoeller commented

Colin, you're unbeatable :-)

spring-projects-issues commented 19 years ago

Colin Sampaleanu commented

Well, if we're going to get into complimenting each other here, I can say the same thing :-) And in your case it's probably even true :-)