* -servlet.xml
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<context:property-placeholder location="classpath*:spring.properties" />
<context:component-scan base-package="com.my.path" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
com.my.path.MyController
@Controller
public class MyController {
@Value("${my.property}")
private String myProperty;
@RequestMapping("/my/path")
public String default(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws Exception {
// Any reference to myProperty above is null...
return "view";
}
}
我在我的 servlet 上下文中确实有其他由 ID 定义的 bean,它们使用我试图通过 Value 注释添加到我的控制器的相同系统属性。我知道他们存在并且具有正确的价值观。所以我不确定为什么我不能让注释工作。