@ImportResource和@PropertySource两个注解的区别
先看第一种方法;@ImportResource
@ImportResource:注解的文件格式和内容应该是xml文件。并且xml内容中必须包含以下信息。
注解:@ImportResource(“classpath:Beans.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd" ><context:property-placeholder location="classpath:/config.properties"/></beans>
第二种方法更加的简单:@PropertySource
只需要加属性的classpath
如:@PropertySource(“classpath:config.properties”)
application.properties的内容如下
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true#jndi数据源名称
spring.datasource.jndi-name=SpringBootDemoDataSource#oracle
#spring.datasource.password=password
#spring.datasource.username=sinospntest
#spring.datasource.url=jdbc:oracle:thin:@172.20.223.252:1521:ORCL
#spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
总结:
@PropertySource 用于引入*.Properties或者 .yml 用于给javabean注入值
@ImportResource 用于引入.xml 类型的配置文件 在spring boot中已经被配置类替代
@PropertySource 一般用在javabean的类名上
@ImportResource一般用于启动类上
@ImportResource和@PropertySource两个注解的区别相关推荐
- spring里面 @Controller和@RestController注解的区别
问题:spring里面 @Controller和@RestController注解的区别 spring里面 @Controller和@RestController注解的区别 Web MVC和REST ...
- MongoDB:SpringBoot有关@Document(collection = )与@Document(collation= )注解的区别
目录 QUESTION:SpringBoot有关@Document(collection = "")与@Document(collation= "")注解的区别 ...
- 详述 @Service 和 @Resource 注解的区别
1 前言 在我们使用 Spring 框架的时候,注解是"不可或缺"的一部分,它帮我们脱离了配置繁琐的 XML 文件的工作,但有一点却需要我们自己去把握,那就是"3何&qu ...
- ASP.NET Get和Post两种提交的区别
表单form的提交有两种方式,一种是get的方法,一种是post 的方法.看下面代码,理解ASP.NET Get和Post两种提交的区别: < form id="form1" ...
- @Autowired注解与@resource注解的区别(十分详细)
背景: 今天下班路上看到一个大货车,于是想到了装配,然后脑海里跳出了一个注解@Autowired(自动装配),于是又想到最近工作项目用的都是@Resource注解来进行装配.于是本着学什么东西都要一钻 ...
- vue 路由传参 params 与 query两种方式的区别(转载)
vue 路由传参 params 与 query两种方式的区别 初学vue的时候,不知道如何在方法中跳转界面并传参,百度过后,了解到两种方式,params 与 query.然后,错误就这么来了: ro ...
- 详述@ResponseBody和@RequestBody注解的区别
2019独角兽企业重金招聘Python工程师标准>>> 1 前言 在详述 @ResponseBody 和 @RequestBody 注解之前,咱先了解一下 @RequestMappi ...
- Java中的string定义的两种方法和区别
java中的String定义的两种方法和区别 第一种:new方式 String s1 = new String("hello world"); String s2 = new St ...
- 【转】IAR与Keil两款开发工具区别
http://www.smzy.com/smzy/tech39675.html IAR及IAR Embedded Workbench,KEIL及Keil MDK-ARM,这两款都是ARM开发工具.那么 ...
最新文章
- Science:致病菌激活根系内生微生物组抵抗病害的功能
- R语言绘图设备dev
- fatal error C1021: 无效的预处理器命令“warning”
- 用Python分析元旦旅游热门城市,告诉你哪些景点性价比更高
- SpringMVC拦截器-用户登录权限控制代码实现3
- Oracle or Question Solve(二)
- 天猫精灵可以当电脑音响吗_阿里投百亿砸天猫精灵,马云的物联网野心能靠智能音箱撑起来吗?...
- SQL基础知识总结(SQL必知必会)
- 原子结构示意图全部_原子结构示意图知识点总结
- appcan java_appcan下载
- 基于 SpringBoot + MyBatis-Plus 的公众号管理系统,接私活必备!
- Android手机ram大小,安卓手机RAM容量演进史,如何从192MB走到16GB,HTC:我有话要说...
- 无法更新运行时文件夹共享状态_关于iPadOS 13.4更新的5件事
- 栈的应用之符号匹配问题
- 星际蜗牛矿难机,j1900 4核+4G内存+16Gssd硬盘,群晖6.1,SSD引导成功
- INDEMIND:多传感器融合,机器人的必由之路
- U盘文件丢失求恢复教程
- 专访王博,国内资深游戏3D角色美术大神
- TikTok不可思议的崛起
- Power BI销售业绩分析