java是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaEE, JavaME, JavaSE)的总称。本站提供基于Java框架struts,spring,hibernate等的桌面应用、web交互及移动终端的开发技巧与资料

保持永久学习的心态,将成就一个优秀的你,来 继续搞起java知识。

第一种:采用$符读取配置文件中的内容

<?<b>xml version</b><b>="1.0" </b><b>encoding</b><b>="UTF-8"</b>?>
<<b>beans</b><b>xmlns</b><b>="http://www.springframework.org/schema/beans" </b><b>xmlns:</b><b>xsi</b><b>="http://www.w3.org/2001/XMLSchema-instance"
</b><b>xmlns:</b><b>context</b><b>="http://www.springframework.org/schema/context"
</b><b>xmlns:</b><b>util</b><b>="http://www.springframework.org/schema/util"
</b><b>xmlns:</b><b>task</b><b>="http://www.springframework.org/schema/task"
</b><b>xsi</b><b>:schemaLocation</b><b>="
</b><b>      http://www.springframework.org/schema/beans </b><b>     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd </b><b>     http://www.springframework.org/schema/context </b><b>      http://www.springframework.org/schema/context/spring-context-3.1.xsd </b><b>      http://www.springframework.org/schema/task </b><b>      http://www.springframework.org/schema/task/spring-task-3.1.xsd </b><b>      http://www.springframework.org/schema/util </b><b>      

' target='_blank'>http://www.springframework.org/schema/util/spring-util-2.0.xsd"[/code]

<!-- 系统环境变量定义 -->
    <<b>context</b><b>:property-placeholder</b><b>location</b><b>="classpath:conf.properties" </b><b>ignore-unresolvable</b><b>="true" </b>/>

<<b>bean</b><b>id</b><b>="dataSource" </b><b>class</b><b>="org.apache.commons.dbcp.BasicDataSource" </b><b>parent</b><b>="parentdataSource"</b>>
    <<b>property</b><b>name</b><b>="url" </b><b>value</b><b>="${jdbc.url}" </b>/>
    <<b>property</b><b>name</b><b>="username" </b><b>value</b><b>="${jdbc.username}" </b>/>
    <<b>property</b><b>name</b><b>="password" </b><b>value</b><b>="${jdbc.password}" </b>/>
</<b>bean</b>>

此方式自动装配方式不能是byName,会出现读取不到配置文件中内容的情况
第二种:采用#方式读取配置文件中的内容

<?<b>xml version</b><b>="1.0" </b><b>encoding</b><b>="UTF-8"</b>?><br/><<b>beans</b><b>xmlns</b><b>="http://www.springframework.org/schema/beans" </b><b>xmlns:</b><b>xsi</b><b>="http://www.w3.org/2001/XMLSchema-instance"<br/></b><b>xmlns:</b><b>context</b><b>="http://www.springframework.org/schema/context"<br/></b><b>xmlns:</b><b>util</b><b>="http://www.springframework.org/schema/util"<br/></b><b>xmlns:</b><b>task</b><b>="http://www.springframework.org/schema/task"<br/></b><b>xsi</b><b>:schemaLocation</b><b>="<br/></b><b>      http://www.springframework.org/schema/beans </b><b>     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd </b><b>     http://www.springframework.org/schema/context </b><b>      http://www.springframework.org/schema/context/spring-context-3.1.xsd </b><b>      http://www.springframework.org/schema/task </b><b>      http://www.springframework.org/schema/task/spring-task-3.1.xsd </b><b>      http://www.springframework.org/schema/util </b><b>      http://www.springframework.org/schema/util/spring-util-2.0.xsd" </b><b>default-autowire</b><b>="byName"</b>><br/>  <!-- 系统环境变量定义 -->
    <<b>context</b><b>:property-placeholder</b><b>location</b><b>="classpath:conf.properties" </b><b>ignore-unresolvable</b><b>="true" </b>/><br/>    <<b>util</b><b>:properties</b><b>id</b><b>="properties" </b><b>location</b><b>="classpath:conf.properties"</b>/>

<<b>bean</b><b>id</b><b>="dataSource" </b><b>class</b><b>="org.apache.commons.dbcp.BasicDataSource" </b><b>parent</b><b>="parentdataSource"</b>>
    <<b>property</b><b>name</b><b>="url" </b><b>value</b><b>="#{properties['jdbc.url']}" </b>/>
    <<b>property</b><b>name</b><b>="username" </b><b>value</b><b>="#{properties['jdbc.username']}" </b>/>
    <<b>property</b><b>name</b><b>="password" </b><b>value</b><b>="#{properties['jdbc.password']}" </b>/>
</<b>bean</b>>

mybatisspring读取配置文件

因为水平有限,难免有疏忽或者不准确的地方,希望大家能够直接指出来,我会及时改正。一切为了知识的分享。

后续会有更多的精彩的内容分享给大家。