学习了spring的数据源的使用以及spring的作用域引入外部属性文件

对应的bean的xml文件和properties文件如下

<?xml version="1.0" encoding="UTF-8"?>
<!-- spring 使用外部属性文件 -->
<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/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <!--
<bean id="datasourse" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="root"></property>
<property name="password" value="000000"></property>
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/javawebholiday?useSSL=false"></property>
</bean> -->
<!-- 导入属性文件 --> <context:property-placeholder location="classpath:db2.properties"/>
<bean id="datasourse" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="jdbcUrl" value="${jdbcUrl}"></property>
</bean> </beans>
user=root
password=
driverClass=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/javawebholiday?useSSL=false
<?xml version="1.0" encoding="UTF-8"?>
<!-- 对于bean的作用于的相关的知识点 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- bean 的作用于是通过scope来显示,配置作用于。
默认是singleton,容器初始化时初始化bean的实例,在整个容器的生命周期只创建这一个bean
prototype原型的,容器创建时初始化时不创建bean的实例,二是在每次的请求。都会创建一个新的bean-->
<bean id="car" class="lib3.Car" scope="prototype">
<property name="price" value=""></property>
<property name="brand" value="adiu"></property>
</bean> </beans>

最新文章

  1. html5,单击显示详细信息
  2. jquery插件-表单验证插件-rules
  3. CSS使用自定义光标样式-遁地龙卷风
  4. sdut 2449走迷宫【最简单的dfs应用】
  5. node.js基础 1之简单的nodejs模块
  6. Linux上构建一个RADIUS服务器详解
  7. Android Studio中Gradle使用详解
  8. TEA算法
  9. JAVA工具_PinyinConv
  10. Maven导入eclipse缺少web-resources目录
  11. Quartz总结(一):Quartz集成Spring的2个方法
  12. 各种排序算法及其java程序实现
  13. C#实现多个PDF合并及去除文字水印功能
  14. 十一、eclipse如何创建一个maven工程project
  15. 阿里巴巴Java开发规约及插件安装
  16. react-native android app名字 app包名、图标和启动图片设置
  17. T-Sql常用语句
  18. public static List SmaDataManager.getThreads(Context context)
  19. Java爬虫——Gecco简单入门程序(根据下一页一直爬数据)
  20. [Android系列—] 4. 加入操作栏(Action Bar)

热门文章

  1. Elasticsearch批量插入时,存在就不插入
  2. Docker 技术系列之安装Docker Desktop for Mac
  3. Netty之缓冲区ByteBuf解读(二)
  4. 【Weiss】【第03章】双链表例程
  5. 使用C#+EmguCV处理图像入门(一)
  6. Fiddler1 简单使用
  7. 简易版cnlog
  8. 动态规划-Minimum Distance to Type a Word Using Two Fingers
  9. 家乐的深度学习笔记「4」 - softmax回归
  10. Mybatis详解系列(一)--持久层框架解决了什么及如何使用Mybatis