spring中的注解

Spring中有很多的注解(annotation),常用的做个总结:

@Value

在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

@Controller

转载于:https://my.oschina.net/u/1786895/blog/297763

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值