您现在的位置是:首页 >

log4j2配置文件详解 详解Spring的配置文件

火烧 2021-10-29 07:52:19 1058
详解S ri g的配置文件   想必用过S ri g的程序员们都有这样的感觉 S ri g把逻辑层封装的太完美了(个人感觉View层封装的不是很好) 以至于有的初学者都不知道S ri g配置文件的意思

详解Spring的配置文件  

  想必用过Spring的程序员们都有这样的感觉 Spring把逻辑层封装的太完美了(个人感觉View层封装的不是很好) 以至于有的初学者都不知道Spring配置文件的意思 就拿来用了 所以今天我给大家详细解释一下Spring的applicationContext xml文件 Ok 还是通过代码加注释的方式为大家演示

  以下是详解Spring的applicationContext xml文件代码

  <! 头文件 主要注意一下编码 >

  <?xml version= encoding= UTF ?>

  <!DOCTYPE beans PUBLIC //SPRING//DTD BEAN//EN beans dtd >

  <beans>

  <! 建立数据源 >

  <bean id= dataSource class= mons dbcp BasicDataSource >

  <! 数据库驱动 我这里使用的是Mysql数据库 >

  <property name= driverClassName >

  <value> mysql jdbc Driver</value>

  </property>

  <! 数据库地址 这里也要注意一下编码 不然乱码可是很郁闷的哦! >

  <property name= url >

  <value>

  jdbc:mysql://localhost: /tie?useUnicode=true&amp;characterEncoding=utf

  </value>

  </property>

  <! 数据库的用户名 >

  <property name= username >

  <value>root</value>

  </property>

  <! 数据库的密码 >

  <property name= password >

  <value> </value>

  </property>

  </bean>

  <! 把数据源注入给Session工厂 >

  <bean id= sessionFactory

  class= springframework orm hibernate LocalSessionFactoryBean >

  <property name= dataSource >

  <ref bean= dataSource />

  </property>

  <! 配置映射文件 >

  <property name= mappingResources >

  <list>

  <value>/alonely/vo/User hbm xml</value>

  </list>

  </property>

  </bean>

  <! 把Session工厂注入给hibernateTemplate >

  <! 解释一下hibernateTemplate hibernateTemplate提供了很多方便的方法 在执行时自动建立 HibernateCallback 对象 例如 load() get() save delete()等方法 >

  <bean id= hibernateTemplate

  class= springframework orm hibernate HibernateTemplate >

  <constructor arg>

  <ref local= sessionFactory />

  </constructor arg>

  </bean>

  <! 把DAO注入给Session工厂 >

  <bean id= userDAO class= alonely dao UserDAO >

  <property name= sessionFactory >

  <ref bean= sessionFactory />

  </property>

  </bean>

  <! 把Service注入给DAO >

  <bean id= userService class= alonely service UserService >

  <property name= userDAO >

  <ref local= userDAO />

  </property>

  </bean>

  <! 把Action注入给Service >

log4j2配置文件详解 详解Spring的配置文件

  <bean name= /user class= alonely struts action UserAction >

  <property name= userService >

  <ref bean= userService />

  </property>

  </bean>

  </beans>

lishixinzhi/Article/program/Java/ky/201311/28542  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码