[jboss-user] [JBoss/Spring Integration] - Re: Is it SpringLifecycleInterceptor or just me?

Arno Werr do-not-reply at jboss.com
Mon Jul 31 11:38:00 EDT 2006


Ales,
I am reading your article 'Spring and EJB 3.0 in Harmony'
Quote:
anonymous wrote : 
  | However, one big problem with EJB 3.0 dependency injection is that there's no way of configuring, defining, and injecting plain Java beans. 
  | You can only inject Java EE component types and <env-entry> only lets you inject primitive types. Sure, EJBs look a lot like POJOs and JBoss has the concept of a @Service bean, which is a singleton, but do we really have to define and inject these component objects that have to run in containers? 
  | And what about beans from third-party libraries and pre-existing code.
  | 
Well, how about this?

  | @Stateless
  | public class OrderEntryBean implements OrderEntry {
  | 	
  | 	@PersistenceContext(unitName = "titan")
  | 	private EntityManager manager;
  | 	
  | 	private PersonDao personDao;
  | 
  | 	@Resource(name = "personDaoImplName")
  | 	private String personDaoImplName;
  | 
  | 	@PostConstruct
  | 	public void postConstruct() {
  | 		try {
  | 	             personDao = (PersonDao) (Class.forName(personDaoImplName))
  | 					.newInstance();
  | 		} catch (Exception e) {
  | 			throw new ValidationException(e);
  | 		}
  | 		personDao.setManager(manager);
  | 	}
  | }
  | 

  | <enterprise-beans>
  | 		<session>
  | 			<ejb-name>OrderEntryBean</ejb-name>
  | 			<env-entry>				<env-entry-name>personDaoImplName</env-entry-name>
  | 				<env-entry-type>java.lang.String</env-entry-type>
  | 				<env-entry-value>
  | 					com.arno.dao.impl.PersonDaoImpl
  | 				</env-entry-value>
  | 			</env-entry>
  |  </session>
  | </enterprise-beans>
  | 

It might be heavy, it might be not-elegant the way Spring provides solution (LOC), injected object cannot be configured externally. But to all practical purposes  as long as a class has an interface it can be injected into EJB and serve the purpose of injection - runtime definition of implementation. Not so? ;)

Cheers,
Arno

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961917#3961917

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961917



More information about the jboss-user mailing list