Hi everyone,

I have a problem with autowiring Spring beans into EJB3. I've read most articles about it (including, of course, Spring documentation), so I know to use SpringBeanAutowiringInterceptor. I believe I have proper configuration as people were saying was OK, for example here: http://forum.springsource.org/showthread.php?t=49267. But everyone uses JBoss 4.2, I'm using 5.0.1.GA, and I think that it makes some difference.

Here's my configuration and code:
EJB:
Code:
package foo.ejb;

import javax.ejb.Stateless;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import foo.dao.SthDAO;
import foo.vo.SthVO;

@Stateless(name = "foo/SessionService", mappedName = "foo/SessionService")
public class SessionServiceEJB implements SessionService {

	private static final Logger logger = Logger.getLogger(SessionServiceEJB.class);

	@Autowired
	private SthDAO sthDAO;

	@Override
	public SthVO getSthById(Long id) {
		logger.debug("getSthById(" + id + "), sthDAO: " + sthDAO);
		return sthDAO.getSthById(id);
	}
}
ejb-jar.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
	<interceptors>
		<interceptor>
			<interceptor-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</interceptor-class>
		</interceptor>
	</interceptors>
	<assembly-descriptor>
		<interceptor-binding>
			<ejb-name>*</ejb-name>
			<interceptor-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</interceptor-class>
		</interceptor-binding>
	</assembly-descriptor>
</ejb-jar>
beanRefContext.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">

	<bean class="org.springframework.context.support.ClassPathXmlApplicationContext">
		<constructor-arg>
			<list>
				<value>applicationContext.xml</value>
			</list>
		</constructor-arg>
	</bean>
</beans>
applicationContext.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"
	default-autowire="byType">
	<context:component-scan base-package="foo" />
	<jee:jndi-lookup id="fooEntityManagerFactory" jndi-name="persistence-units/foo"/>
</beans>
I see, that Spring is being used, because in logs I can see:
Code:
INFO  [NamedXmlApplicationContext] Bean factory for application context [org.jboss.spring.factory.NamedXmlApplicationContext@1e0a078]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1c56526
But any try to use EJB3 from Tomcat ends with (Tomcat side):
Code:
Caused by: org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.springframework.beans.factory.BeanFactory] is defined: expected single bean but found 0
Has anyone managed to autowire anything into EJB3 on JBoss5? I need that in EAR archive.

Regards

Jacek Bilski