springMvc的项目中,通过注解@Value获取properties配置文件中的配置,使用该注解必须引入的包:

spring-beans-4.1.4.RELEASE.jar

下面是需要在spring的配置文件中配置的内容

<?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"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:config/autoCreateTable.properties</value>
</list>
</property>
</bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties" />
</bean>
</beans>
---------------------
作者:孙琛斌
来源:CSDN
原文:https://blog.csdn.net/sun5769675/article/details/51789352
版权声明:本文为博主原创文章,转载请附上博文链接!

然后创建组件,通过注解获取配置文件的值

 /**
* 要扫描的model所在的pack
*/
@Value("#{configProperties['mybatis.model.pack']}")
private String pack; /**
* 自动创建模式:update表示更新,create表示删除原表重新创建
*/
@Value("#{configProperties['mybatis.table.auto']}")
private String tableAuto;
---------------------
作者:孙琛斌
来源:CSDN
原文:https://blog.csdn.net/sun5769675/article/details/51789352
版权声明:本文为博主原创文章,转载请附上博文链接!

configProperties就是bean的id,[”]中的值就是要取的配置文件中的key,这样就可以将配置文件中的值映射到代码中的pack、tableAuto属性上了。

然后直接注入这个组件就可以了。

原文链接:https://blog.csdn.net/sun5769675/article/details/51789352

springMvc中获取通过注解获取properties配置文件(转)的更多相关文章

  1. springmvc在使用@ModelAttribute注解获取Request和Response会产生线程并发不安全问题(转)

    springmvc在获取Request和Response有很多方式:具体请看:https://www.cnblogs.com/wade-luffy/p/8867144.html 产生线程问题的代码如下 ...

  2. 在springMVC中使用自定义注解来进行登录拦截控制

    1:java注解使用是相当频繁,特别是在搭建一些框架时,用到类的反射获取方法和属性,用的尤其多. java中元注解有四个: @Retention     @Target     @Document  ...

  3. SpringMVC中的常用注解

    RequestParam 作用: 用于  将请求参数区数据  映射到  功能处理方法的参数上. 属性: value  请求参数中的名称 required   请求参数中是否必须提供此参数. 默认值: ...

  4. spring注解注入properties配置文件

    早期,如果需要通过spring读取properties文件中的配置信息,都需要在XML文件中配置文件读取方式. 基于XML的读取方式: <bean class="org.springf ...

  5. 关于springmvc中常用的注解,自己也整理一下

    1.@Controller 在springMVC中@controller主要用在控制层的类上,之前只知道用注解开发的时候必须加一个@controller ,今天看了别的大佬整理的才知道为什么这么用,控 ...

  6. springMVC中不通过注解方式获取指定Service的javabean

    如TestService,其实现为TestServiceImpl,则可以通过 TestService testService = (TestService)SpringContextHolder.ge ...

  7. springmvc 中常用的注解配置使用说明

    很久没有用springmvc了,今天复习了一下,然后记录一下总结. @Controller     使用 @Controller 注释对将成为 MVC 中控制器的类进行注释并处理 HTTP 请求. @ ...

  8. 在springmvc中无法使用@value()注解

    折腾了一下午,试了很多解决办法,就是死活不能扫描到properties文件.本来打算使用软编码的,尝试更改了全部jar包版本,还是无法解决. 后面想到了,spring和springmvc容器的加载顺序 ...

  9. springmvc中的全注解模式

    1.贴在类上: @Controller表明其是一个控制器 2.贴在方法上: @requestMapping("/xxx"): 标明请求要访问的方法的资源路径,,需以/打头.其中省略 ...

随机推荐

  1. [人物存档]【AI少女】【捏脸数据】少(烧)女前(钱)线

    点击下载(城通网盘):9.zip 点击下载(城通网盘):AISChaF_20191112224605286.png

  2. Python黑科技:赋值技巧

    一个变量一个值(正常赋值) v = 1 ''' # 结果,v: 1 ''' 多个变量一个值(连续赋值) x = y = z = 0 ''' # 结果,x: 0, y: 0, z: 0 ''' # 注意 ...

  3. js几种加密方法

    1.base64加密 它的github地址:https://github.com/dankogai/js-base64 <!DOCTYPE HTML> <html> <h ...

  4. C++入门经典-例2.13-左移运算

    1:代码如下: // 2.13.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> using ...

  5. js创建对象的6种方式总结

    1.new 操作符 + Object 创建对象 var person = new Object(); person.name = "lisi"; person.age = 21; ...

  6. shiro的Quickstart

    /** * Simple Quickstart application showing how to use Shiro's API. * * @since 0.9 RC2 */ public cla ...

  7. 第十三周Java课程学习总结

    学习总结: 记事本界面: 监听适配器. 可以通过Window Adapter来实现监听. void windowActivated(WindowEvent e) 激活窗口时调用. void windo ...

  8. BuiltIn库

    简介 作为一门表格语言,为了保持简单的结构,RF没有像别的高级语言那样提供类似ifelsewhile等内置关键字来实现各种逻辑功能(注1),而是提供给了用户BuiltIn库.如果用户想在测试用例中实现 ...

  9. 统计学_样本量估计_python代码实现

    python机器学习-乳腺癌细胞挖掘(博主亲自录制视频)https://study.163.com/course/introduction.htm?courseId=1005269003&ut ...

  10. spring BeanUtils.copyProperties只拷贝不为null的属性

    在MVC的开发模式中经常需要将model与pojo的数据绑定,apache和spring的工具包中都有BeanUtils,使用其中的copyProperties方法可以非常方便的进行这些工作,但在实际 ...