Closed spring-projects-issues closed 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
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...
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
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.
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
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.
Juergen Hoeller commented
Colin, you're unbeatable :-)
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 :-)
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:
becomes
\
\
\
\\SimpleWithCmtAndNoSpringTx\ \
\\false\ \
\
\
\
\org.springframework.autobuilds.ejbtest.simple.ejb.SimpleHomeRemote\
\
\
That's way too much work, in my opinion...
Affects: 1.1.2