Inject spring bean into CDI(weld) bean - spring

I have see articles around how we can inject spring beans into JSF managed bean. We don't use JSF managed bean but use CDI(Weld) bean. How can we inject spring bean into CDI(weld) bean.

Related

CDI #ApplicationScoped bean in Spring

I have a CDI bean that is annotated with #ApplicationScoped. Is there a way to tell Spring to pick it up during component scan, as if it were annotated with #Component? Spring does understand the #Inject annotation so why not #ApplicationScoped?
The idea is that it would be handy to use CDI beans in Spring (at least if they only use plain dependency injection without the fancy CDI stuff like interceptors, decorators...)
It is not entirely clear how is your code structured, if possible just annotate it with #Component as well. A component bean in Spring has similar properties as an application scoped bean. The default scope of a bean in Spring is singleton and it can be proxied, similar to what #ApplicationScoped would offer.
Spring does understand the #Inject annotation so why not #ApplicationScoped?
Spring offers support for JSR 330 annotation, #ApplicationScoped is nor part of those.

SpringBeanFacesELResolver not working with spring WebFlow

I added SpringBeanFacesELResolver to my faces-config.xml but always when I am trying to inject property using #ManagedProperty the injection field is null.
Do you know if SpringBeanFacesELResolver works together with Spring WebFlow?
I had some problems injecting spring beans to manage beans with #ManagedProperty, i had also SpringBeanFacesELResolver the problem was that the beans have the #Transactional annotation and this beans has no interface when i created the interface and use the interface in the manage bean the injection was done, maybe this help you but i'm not using spring webflow
Note: I want to write this as comment but i don't know why i couldn't

When is Spring bean destroyed by default?

By default Spring beans are singletons, so are beans destroyed if application is shut-down? Or is there any bean time-out?

How do I inject declarative service into my spring bean

I have a third party lib which is exposing declarative service. But I have a spring bean class.
How do I inject this declarative service into my spring bean class?
You must declare this service also as a bean so it can be managed by spring.

jsf2 spring managed bean calling constructor and postconstruct only on tomcatstartup

I am using JSF+Spring project my spring maanged bean is ViewScoped
my saving state is client.
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
Following is my bean i found that constructor of bean and postconstruct method got call only on tomcat startup when it is spring managed bean instead if it is JSF managed bean constructor and postconstruct got call on every page refresh.
Is it the real behavior if i want to call method on page refresh every time under spring managed bean what should id do ?
#Component
#ViewScoped
public class DataTableBean implements Serializable{
public DataTableBean() {
super();
}
#PostConstruct
private void loadDataData(){
System.out.println("Post constructing");
}
}
The #Component is a Spring specific annotation to manage beans by Spring. The #ViewScoped is a JSF specific annotation to specify the scope of a JSF managed bean #ManagedBean. JSF specific scope annotations does not work on a Spring managed bean at all. You should use the Spring specific #Scope annotation instead.
So, either just manage the bean by JSF:
#ManagedBean
#ViewScoped
Or homegrow a Spring "view" scope (this is namely not one of the default scopes available in Spring):
#Component
#Scope("view")

Resources