applicationContext.xml中的使用${}是代表什么意思?

在applicationContext.xml文件中,使用 ${xxx} 表示的是:调用某个变量,该变量的名称就是{xxx}里面的"xxx"。

例如:在applicationContext.xml文件中配置数据连接池

  1. <!-- 配置数据链接池 -->
  2. <property name="dataSource">
  3. <bean class="com.mchange.v2.c3p0.ComboPooledDataSource">
  4. <property name="jdbcUrl" value="${jdbcUrl}"></property>
  5. <property name="driverClass" value="${driverClass}"></property>
  6. <property name="user" value="${user}"></property>
  7. <property name="password" value="${password}"></property>
  8. <!-- 其它配置 -->
  9. <!-- 初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default:3 -->
  10. <property name="initialPoolSize" value="3"></property>
  11. <!-- 连接池中保留的最小连接数。Default:3 -->
  12. <property name="minPoolSize" value="3"></property>
  13. <!-- 连接池中保留的最大连接数。Default:15 -->
  14. <property name="maxPoolSize" value="15"></property>
  15. <!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default:3 -->
  16. <property name="acquireIncrement" value="3"></property>
  17. <!--
  18. 控制数据源内加载preparedStatement数量.如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default:0
  19. -->
  20. <property name="maxStatements" value="8"></property>
  21. <!--
  22. maxStatementsPerConnection 定义了连接池内单个连接所拥有的最大缓存statements数。Default:0
  23. -->
  24. <property name="maxStatementsPerConnection" value="5"></property>
  25. <!-- 最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default:0 -->
  26. <property name="maxIdleTime" value="1800"></property>
  27. </bean>
  28. </property>

代码中被标识的部分就是使用了${}的功能。它相当于Java中调用了变量名一样。

在本例子中,这些变量来自另外一个properties文件。该properties为: jdbc.properties(主要用来存放JDBC连接数据库的一些配置,方便下次修改,而不需要在applicationContext.xml文件中修改。)

jdbc.properties:

  1. jdbcUrl=jdbc:mysql://localhost:3306/oa
  2. driverClass=com.mysql.jdbc.Driver
  3. user=root
  4. password=

${jdbcUrl} 中的jdbcUrl 指的就是jdbc.properties中jdbcUrl。

来自为知笔记(Wiz)

时间: 2024-08-26 23:59:26

applicationContext.xml中的使用${}是代表什么意思?的相关文章

spring controller中@Value取不到applicationContext.xml中加载配置文件的问题

原因还未查证: http://sunjun041640.blog.163.com/blog/static/256268322014127113844746/ 在使用spring mvc时,实际上是两个spring容器: 1,dispatcher-servlet.xml 是一个,我们的controller就在这里,所以这个里面也需要注入属性文件 org.springframework.web.servlet.DispatcherServlet 这里最终是使用WebApplicationContex

applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.

我用的jeesite框架,在使用定时任务时,出现一些问题,,1.在windows上项目可以在tomcat下,运行2.在linux下项目在tomcatgh下,却出现问题: 15-Dec-2017 15:15:37.552 INFO [www.toolcoo.com-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext2017-12-15

在application-context.xml中配置多个property-placeholder

如下所示,直接写多个<context:property-placeholder>标签是会报错的. <context:property-placeholder location="classpath:wechat/official-account.properties" /> <context:property-placeholder location="classpath:db.properties" /> 即便是写在不同的xml

Hibernate中持久化注解的java文件在applicationContext.xml中的配置

之前用Hibernate操作数据库,都是写下.hbm.xml配置文件的.这段时间发现注解要比.hbm.xml方便很多时,决定用注解. 之前用.hbm.xml时,在applicationContext.xml里配置是: <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="da

applicationContext.xml 中 &lt;ref bean=&quot;&quot;&gt; 与 &lt;ref local=&quot;&quot;&gt;的区别

第一步:创建工程   FirstSpringJAVA 第二步:新建dao层类 Dao.java package com.xuzhiwen.spring10; public class Dao { public void save(){ System.out.println("Dao.save()..."); } } 第三步:新建service类,将dao通过set的方式注入到 service中 ServiceTest.java package com.xuzhiwen.spring10

SpringMVC之application-context.xml,了解数据库相关配置

上一篇SpringMVC之web.xml让我们了解到配置一个web项目的时候,如何做基础的DispatcherServlet相关配置,作为SpringMVC上手的第一步,而application-context.xml则让我们了解到如何将数据库信息加载到项目中,包含关键的数据库连接信息.sqlSessionFactory.事务等关键因素. ①.xml内容 <?xml version="1.0" encoding="UTF-8"?> <beans x

Web环境下applicationContext.xml文件配置

在web环境下(web.xml)如何配置applicationContext.xml文件 <listener>  <listener-class>   org.springframework.web.context.ContextLoaderListener  </listener-class> </listener> 或: <servlet>  <servlet-name>context</servlet-name>  

为什么applicationContext.xml和spring-servlet.xml中都有注解过滤&lt;context:component-scan base-package=&quot;myproject&quot;&gt; 和&lt;context:component-scan base-package=&quot;myproject.controller&quot; /&gt;

在刚学习SpringMVC框架整合时,你也许会产生疑问为什么Spring.xml和SpringMVC.xml中都有注解过滤. <context:component-scan base-package="myproject"> 和<context:component-scan base-package="myproject.controller" /> 在这里有一个比较有意思的问题,初学者也会产生困惑,那么他究竟有何不同?我思考和查询很久,话不

@Value取不到值引出的spring的2种配置文件applicationContext.xml和xxx-servlet.xml

项目中经常会用到配置文件,定义成properties的形式比较常见,为了方便使用一般在spring配置文件中做如下配置: <context:property-placeholder ignore-unresolvable="true" location="classpath*:/application.properties" /> 这样在程序代码中直接用@Value("${name}")就能直接取到properties文件中定义的变量