我对Spring有些新奇(使用3.0),所以我希望有一个简单的答案。如果我有一个使用@Controller和@RequestMapping注释的控制器,并且我想通过依赖注入来设置一个属性,那我该怎么做呢?控制器类不必出现在Spring配置文件中,因为它被@Controller注释自动拾取。
示例Controller类:
package gov.wi.dnr.wh.web.spring;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class RehabHomeController {
private String xxx;
@RequestMapping(value="/rehab/home", method = RequestMethod.GET)
public String get() {
return "whdb.rehabhome";
}
public String getXxx() {
return xxx;
}
public void setXxx(String xxx) {
this.xxx = xxx;
}
}
弹簧配置
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
这是正常的,但我想注入“xxx”属性。我该怎么做呢?