[英]How to modularize a JSF/Facelets/Spring application with OSGi?
[英]How to use JSF annotations in Spring+JSF application
我想在JSF ManagedBean中注入spring bean。 現在我使用:applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="service" class="com.evgeny.domain.TestService"></bean>
</beans>
face-config.xml:
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
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/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
<managed-bean>
<managed-bean-name>facesBean</managed-bean-name>
<managed-bean-class>com.evgeny.jsf.FacesBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>service</property-name>
<value>#{service}</value>
</managed-property>
</managed-bean>
</faces-config>
...而且有效。 但是我想對JSF bean使用注釋。 那么如何在@ManagedBean
注釋的bean中注入TestService
?
您可以使用@ManagedProperty
通過注入
@ManagedProperty(value="#{testService}")
private TestService testService;
就像使用注釋一樣定義服務實現
@Service(value = "testService")
public class TestServiceImpl implements TestService
當您在xml文件中定義了bean時,可以用該bean id替換@ManagedProperty
注入中的值
希望這可以幫助 !!!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.