`
wandejun1012
  • 浏览: 2693783 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

spring @value resource

 
阅读更多

 

看个例子:

@Value("rules.xml")
private Resource ruleConfig;

 

spirng会读取这个配置文件,然后尝试帮你生成Resource对象。

 

 

其中,value括号中的参数可以是字符串,也可以用el表达式,形如${}。

注意:classpath放在其中有可能是识别不了的。

 

el表达式例子:http://stackoverflow.com/questions/7019642/injecting-a-classpath-resource-into-a-spring-3-bean

 

用classpath也可以的例子:http://stackoverflow.com/questions/7484594/spring-3-0-inject-files-as-resources

 

el表达式例子2:http://www.mkyong.com/spring3/spring-value-default-value/、

 

el表达式例子3:http://9leg.com/spring/2015/02/12/spring-propertysource-value-annotations-example.html

 

 

 

分享到:
评论

相关推荐

    Spring注解 - 52注解 - 原稿笔记

    在火狐中显示可能会有问题,大家都是... @RequestMapping , @RequestParam , @Resource , @ResponseBody , @RestController , @Scope , @Service , @Validated , @Value , @WebFilter , @WebInitParam , @WebListener

    spring4框架系列 [ 5 ]

    spring4框架系列 [ 5 ] 基于注释注入@Component @Value @Resource @Autowired @PostConstruct @PreDestroy

    Spring Boot最常用的30个注解.docx

    1 @Resource 2 @Autowired 3 @Qualifier 4 @value 5 @ConfigurationProperties 四、 HTTP请求相关 1 @GetMapping 2 @PostMapping 3 @RequestMapping 五、 前后端传值相关 1 @PathVariable 2 @RequestParam 3 @...

    SpringBoot常用注解详解含使用示例(值得珍藏)

    本文将详细介绍Spring Boot中最常用的注解,包括@SpringBootApplication、@Component、@Service、@Repository、@Controller、@RequestMapping、@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@Autowired...

    springframework.4.3.22.RELEASE

    Spring JavaMailSenderImpl does not show proper message when recipient list is empty [SPR-17540] #22072 Potential resource leak in DataSourceUtils.doGetConnection [SPR-17559] #22091 SpEL, error parsing...

    基于注解的DI.docx

    常用注解: @Component、创建对象 @Respotory、创建dao对象,用来访问数据库 @Service、创建Service对象,处理...@Resource、jdk中的注解,使用自动注入给引用数据类型赋值,支持byName、byType,默认byName

    springjdbc

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context=...

    Spring入门笔记.md

    ## Spring入门学习 首先认识下Spring的结构 ![架构图]... <property name="name" value="Yiibai" /> ``` list Map,provincecitymysqq

    Spring2.5的国际化配置

    使用Spring的MVC,并且配置中有配置Resource文件 <!-- 资源文件绑定器 --> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" ...

    spring基础

    @Resource 有两个属性是比较重要的,分别是 name 和 type,Spring 将 @Resource 注释的 name 属性解析为 Bean 的名字,而 type 属性则解析为 Bean 的类型。所以如果使用 name 属性,则使用 byName 的自动注入策略,...

    springframework.5.0.12.RELEASE

    @Value Optional<...> field injection fails in case of registered ConversionService [SPR-17607] #22139 @Profile mishandles "not" operand mixed with "&" [SPR-17606] #22138 SpEL, error parsing big ...

    Spring攻略(第二版 中文高清版).part1

    1.12 用@Autowired和@Resource自动装配Bean 41 1.12.1 问题 41 1.12.2 解决方案 41 1.12.3 工作原理 41 1.13 继承Bean配置 47 1.13.1 问题 47 1.13.2 解决方案 47 1.13.3 工作原理 48 1.14 从...

    spring-boot-reference.pdf

    Resource Conditions 46.3.5. Web Application Conditions 46.3.6. SpEL Expression Conditions 46.4. Testing your Auto-configuration 46.4.1. Simulating a Web Context 46.4.2. Overriding the Classpath 46.5....

    Logincontroller.java

    import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.jdbc.core.JdbcTemplate; import org.spring...

    Manning.Spring.in.Action.4th.Edition.2014.11.epub

    Praise for the Third Edition of Spring in Action Preface Acknowledgments About this Book 1. Core Spring Chapter 1. Springing into action 1.1. Simplifying Java development 1.1.1. Unleashing the power ...

    Spring攻略(第二版 中文高清版).part2

    1.12 用@Autowired和@Resource自动装配Bean 41 1.12.1 问题 41 1.12.2 解决方案 41 1.12.3 工作原理 41 1.13 继承Bean配置 47 1.13.1 问题 47 1.13.2 解决方案 47 1.13.3 工作原理 48 1.14 从...

    Spring.net框架

    在Step3到Step5的例子中,我们将利用Spring.net提供的Ioc框架,轻松完 成解耦以及系统改造等工作。 一、类之间的依赖 我们的第一个例子主要用于说明程序的基本构造,并且作为一个反面典型,引出为什么要解耦,以及...

    Struts2+Spring3+MyBatis3完整实例

    , [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules....

    Spring.html

    Resource Value 声明周期 Scope PostConstruct PreDestroy 新注解 Bean:写方法上,将方法的返回值 Configuration:标记配置类 ComponentScan包扫描 PropertySource:加载配置文件 Import:导入...

    springmybatis

    mybatis实战教程mybatis in action之五与spring3集成附源码 mybatis实战教程mybatis in action之六与Spring MVC 的集成 mybatis实战教程mybatis in action之七实现mybatis分页源码下载 mybatis实战教程mybatis in ...

Global site tag (gtag.js) - Google Analytics