相关疑难解决方法(0)

JSF 2使用@ManagedProperty注入Spring bean/service而没有xml

我想使用jsf注释和一些spring注释将spring bean/service注入jsf托管bean.(在jsf bean上我只想使用jsf注释)我不想使用像@named/ 这样的注释@inject.

我试图在网上找到一个解决方案,但没有任何运气.

@ManagedBean
@ViewScoped 
public class MyBean {

    @ManagedProperty(value = "#{mySpringBean}")
    private MySpringBean mySpringBean;

    public void setMySpringBean(MySpringBean mySpringBean) {
        this.mySpringBean = mySpringBean;
    }

    public void doSomething() {
    //do something with mySpringBean
    }
}
Run Code Online (Sandbox Code Playgroud)

没有使用xml就可以实现这样的功能.例如,我不想使用类似的东西

FacesContextUtils.getWebApplicationContext(context).getBean("MySpringBean");
Run Code Online (Sandbox Code Playgroud)

或者在 faces-config.xml

<managed-bean>
    <managed-bean-name>myBean</managed-bean-name>
    <managed-bean-class>com.mytest.MyBean</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
    <managed-property>
        <property-name>mySpringBean</property-name>
        <value>#{mySpringBean}</value>
    </managed-property>
</managed-bean>
Run Code Online (Sandbox Code Playgroud)

是否可以使用注释,并且没有为config xml文件中的每个bean定义所有jsf bean/properties和spring beans/properties?

java jsf spring annotations jsf-2

15
推荐指数
2
解决办法
3万
查看次数

标签 统计

annotations ×1

java ×1

jsf ×1

jsf-2 ×1

spring ×1