Notice: Problem already solved, currently I can't post the answer but just posted to inform for a rare case. See comment at bottom. Thnx
I am trying to inject a spring bean into JSF bean as managed property. No exception is thrown when JSF Bean is initialized. But ManagedProperty is null. I put some logs on setter method, but it seems it is never called. But I can get the Spring bean via at @Postconstruct method:
WebApplicationContext webAppContext = ContextLoader.getCurrentWebApplicationContext();
modelOperations = (ModelOperations) webAppContext.getBean("modelOperations");
PS: I know there are many similar threads, spent whole day, but exhausted reading them ending up with no clue why it is not working
Environment: Spring 3.2.1, JSF: 2.2.4, Jetty on Eclipse
@ManagedBean(name = "batchOperation")
@SessionScoped
public class BatchOperation implements Serializable {
@ManagedProperty(value = "#{modelOperations}", name = "modelOperations")
ModelOperations modelOperations;
@PostConstruct
public void prepareLazyDataModel() {
..
List<XXX> list = modelOperations.getXXXList()
..
}
public ModelOperations getModelOperations() {
return modelOperations;
}
public void setModelOperations(ModelOperations modelOperations) {
this.modelOperations = modelOperations;
}
}
ModelOperations bean:
package xxxxx.dao;
@Component(value = "modelOperations")
@Scope("prototype")
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, value = "transactionManager")
public class ModelOperationsImpl implements ModelOperations {
protected SessionFactory sessionFactory;
}
faces.config:
<?xml version="1.0" encoding="utf-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
applicationContext.xml:
<context:annotation-config/>
<context:component-scan base-package="xxxxx"
name-generator="xxxxx.util.WithoutTrailingImplBeanNameGenerator">
<context:include-filter type="regex"
expression="xxxxx.dao.*" />
</context:component-scan>
(Put that if anybody wonders) WithoutTrailingImplBeanNameGenerator:
public class WithoutTrailingImplBeanNameGenerator extends
AnnotationBeanNameGenerator {
public String generateBeanName(BeanDefinition definition,
BeanDefinitionRegistry registry) {
String beanName = super.generateBeanName(definition, registry);
if (!beanName.endsWith("Impl")) {
return beanName;
}
return beanName.substring(0, beanName.length() - "Impl".length());
}
}