jsf使用spring注入的bean

jsf的后台bean中使用spring定义的service,需要使用@ManagedProperty,并且要具有该属性的getter/setter方法。

package cn.catr.lm.idc.controller;

import cn.catr.lm.idc.service.UserService;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped; @ManagedBean(name = "testBean")
@ViewScoped
public class TestController implements Serializable{ @ManagedProperty(value = "#{userService}")
private UserService userService; private String user; @PostConstruct
private void init() {
user = userService.save();
System.out.println("ok.");
} public String getUser() {
return user;
} public UserService getUserService() {
return userService;
} public void setUserService(UserService userService) {
this.userService = userService;
} }
上一篇:Webservice详解


下一篇:字符串多模匹配---最左优先