tags:

views:

296

answers:

3

I need to inject a Spring bean into a Seam context. Unless I declare the spring bean as a EJB, I cannot get it injected into other seam-managed components. But when I do this, all the spring injected fields are usless cause Seam creates new instances at run-time.

I also tried to add the <seam:component/> element to the spring bean definition and tried to inject it in the container with the @In("beanId") annotation in the target class but I always end up with a NullpointerException...

EDIT:

I read the online articles and did as they say. My spring component is also added to the seam context (I can tell, cause when I define one with the same ID in seam, it complains). Looks like @In is not picking up....

+3  A: 

Have you read this chapter? It should tell you exactly what to do.

Bozho
+1  A: 

Raoul,

Although i do not use Seam along with Spring, chapter 15 of Seam In Action books talks about Spring integration. It is free and is updated.

You have said

I also tried to add the element to the spring bean definition and tried to inject it in the container with the @In("beanId")

Seam in Action book says

The EL expression used in the @In annotation, #{tournamentManager}, resolves to an equivalently named bean in the Spring container, courtesy of the delegating variable resolver

Do you have to use @In("#{beanId}") instead of @In("beanId"), do not ?

I have seen

By default, <seam:component/> will create a STATELESS Seam component with class and name provided in the bean definition.

<bean id="someSpringBean" class="SomeSpringBeanClass" scope="prototype">
    <seam:component/>
</bean>

And

The scope attribute of <seam:component/> may be used if you wish the Spring bean to be managed in a particular Seam scope. The Spring bean must be scoped to prototype if the Seam scope specified is anything other than STATELESS.

Have you done as above ?

Arthur Ronald F D Garcia
Thanks, I read exactly this but it doen't work (yet)...
raoulsson
Yes, I did all that. With EL, without EL. Going to setup a SeamTest now...
raoulsson
A: 

I have a project using Seam + Spring and I have to set @In(create=true) when I want to inject a Spring bean into my Seam component otherwise I get a NullPointerException, you should try it.

kpolice