Spring中有很多的注解(annotation),常用的做个总结:
在applicationContext.xml中加入:
<import resource="classpath:applicationContext-property.xml" />
在applicationContext-property.xml中加入:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<!-- Application Properties -->
<util:properties id="application" location="classpath:application.properties"/>
</beans>
在application.properties中:
加入键值对:
deploy.phase=release
key=value
test.abc = 111
。。。
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("/admin/images")
@Controller
public class ImageAdminController {
private String imageDir;
@Value("#{settings['test.abc']}")
public void setImageDir(String val) {
this.imageDir = val;
}
}
这样test.abc的值就被注入了。
@RequestMapping