Spring导入外部资源
- 创建一个数据库连接的 properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?serverTimezone=Asia/Shanghai&useSSL=true&useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=admin888
- 创建ApplicationContext.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:con="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- 导入外部资源-->
<!-- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">-->
<!-- <property name="location" value="classpath:datasourse.properties"/>-->
<!-- </bean>-->
<con:property-placeholder location="classpath:datasourse.properties"/>
<bean id="datasource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>
这里导入资源有两种方式,选择一种即可
- 第一种:已经过时了!
<!-- 导入外部资源-->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:datasourse.properties"/>
</bean>
- 第二种:Spring推荐使用的
<con:property-placeholder location="classpath:datasourse.properties"/>
- 创建一个测试类
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MyTest {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
DruidDataSource datasource = context.getBean("datasource", DruidDataSource.class);
System.out.println(datasource);
}
}
- 运行结果

Spring导入外部资源的更多相关文章
- Spring Boot 外部化配置(二) - @ConfigurationProperties 、@EnableConfigurationProperties
目录 3.外部化配置的核心 3.2 @ConfigurationProperties 3.2.1 注册 Properties 配置类 3.2.2 绑定配置属性 3.1.3 ConfigurationP ...
- spring mvc 静态资源 404问题
spring mvc 静态资源 404问题 在web.xml配置servlet-mapping的时候,如果url-pattern设置为"/" (如下),很多人都会遇到导入js,cs ...
- springmvc:BeanNameViewResolver访问内部资源视图对象和访问外部资源视图对象
<!-- 处理器映射器 --> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerM ...
- Spring Boot 外部化配置(一)- Environment、ConfigFileApplicationListener
目录 前言 1.起源 2.外部化配置的资源类型 3.外部化配置的核心 3.1 Environment 3.1.1.ConfigFileApplicationListener 3.1.2.关联 Spri ...
- spring访问静态资源出错,No mapping found for HTTP request with URI xxx/resources/js/jquery.min.js...
问题:spring访问静态资源出错,No mapping found for HTTP request with URI xxx/resources/js/jquery.min.js... web.x ...
- Error #2044: 未处理的 IOErrorEvent:。 text=Error #2035: 找不到 URL这是flash加载外部资源时有时会遇到的问题,对于此问题解决如下
导致这个错误的主要原因是未添加IOErrorEvent事件监听,或者添加了监听,但是加载时使用了unload() 参考资料: http://blog.csdn.net/chjh0540237/arti ...
- CAD二次开发---导入外部文件中的块并输出预览图形(五)
思路: 1)首先要定义一个数据库对象来表示包含块的文件,改数据库对象会被加载到内存中,但不会被显示在CAD窗口中. 2)调用Database类的ReadDwgFile函数将外部文件DWG文件读入到新创 ...
- Spring Boot 静态资源处理
spring Boot 默认的处理方式就已经足够了,默认情况下Spring Boot 使用WebMvcAutoConfiguration中配置的各种属性. 建议使用Spring Boot 默认处理方式 ...
- js导入外部脚本文件
JS 语言没找到导入外部脚本文件的功能,只能通知宿主程序来处理. function include(path){ var a=document.createElement("script&q ...
随机推荐
- 我的excel是2003版本的,里边有sheet1、sheet2两个工作表,当使用GetOleDbSchemaTable获取表Schema时,结果是4个,分别为: sheet1 sheet1$ sheet2 sheet2$
原帖地址:http://bbs.csdn.net/topics/310230098 ---------------------------------------------------------- ...
- Getting Started With Node and NPM
Getting Started with Node and NPM Let's start with the basics. Install Node.js: https://nodejs.org.
- SQL——SQL函数
avg(col) -- 返回数值列的平均值,NULL值不包括在计算中.count(col) -- 返回指定列的值的数目,NULL不计入:count(*)返回表中记录数:count(distinct c ...
- dede列表页限制标题长度
{dede:list pagesize ='10' titlelen="45"} <li><a href="[field:arcurl/]"& ...
- JNPF低代码开发框架代码生成器设计
1.代码生成器目录下有通用开发模板.单表开发模板.多表开发模板.流程表单模板.移动开发模板等: ①代码生成器录下通用开发模板页面,有搜索.上步.下步.下载代码功能操作: ②输入查询条件表名关键字进行搜 ...
- 剑指Offer之链表中倒数第k个结点
题目描述 输入一个链表,输出该链表中倒数第k个结点. 思路:首先计算出链表的长度,再计算出倒数第k个是正数第几个,找到该结点即可. public ListNode FindKthToTail(Li ...
- Matlab矩阵学习二 矩阵的修改
Matlab矩阵的修改 一.元素修改 (1).矩阵扩充 (2)矩阵删除某行或某列 删除某行:A(m,:)=[] %删除A矩阵的第m行 删除某列: A(:,n)=[] %删除A矩阵的第n列 ...
- VC程序设计--文字输出方法与字体示例
在用户窗口上输出一个扇形,并在扇面竖向输出一首唐诗.本例使用绝对定位确定输出文字的位置,并采用多种自定义字体输出文字. // poemDemo.cpp : 定义应用程序的入口点. // #includ ...
- 分布式 ID 的 9 种生成方式
为什么要用分布式ID? 在说分布式ID的具体实现之前,我们来简单分析一下为什么用分布式ID?分布式ID应该满足哪些特征? 什么是分布式ID? 拿MySQL数据库举个栗子: 在我们业务数据量不大的时候, ...
- Rocket - tilelink - ProbePicker
简单介绍ProbePicker的实现. 1. 基本介绍 用于把多个Cache client合并成一个: 2. diplomacy node ProbePicker的 ...