spring 简单配置

<?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:context="http://www.springframework.org/schema/context"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
 default-autowire="byName" default-lazy-init="true">

 <!-- 配置数据源 -->
 <bean id="dataSource"
  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName">
   <value>com.mysql.jdbc.Driver</value>
  </property>
  <property name="url">
   <value>
    jdbc:mysql://localhost/ssh?characterEncoding=utf-8
   </value>
  </property>
  <property name="username">
   <value>root</value>
  </property>
  <property name="password">
   <value>123</value>
  </property>
 </bean>

 <!--配置SessionFactory -->
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="dataSource" />
  </property>
  <property name="mappingResources">
   <list>
    <value>com/ssh/pojo/User.hbm.xml</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.show_sql">true</prop>
   </props>
  </property>
 </bean>

 <!-- 事务管理 -->
 <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
 </bean>

 <!-- hibernateTemplate -->
 <bean id="hibernateTemplate"
  class="org.springframework.orm.hibernate3.HibernateTemplate">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
 </bean>

 <!-- 配置数据持久层 -->
 <bean id="userDao"
  class="com.ssh.dao.impl.UserDaoImpl">
  <property name="hibernateTemplate" ref="hibernateTemplate"></property>
 </bean>

 <!-- 配置业务逻辑层 -->
 <bean id="userService"
  class="com.ssh.service.impl.UserServiceImpl">
  <property name="userDao" ref="userDao"></property>
 </bean>

 <!-- 配置控制层 -->
 <bean id="UserAction"
  class="com.ssh.action.UserAction"  scope="prototype">
  <property name="userService" ref="userService"></property>
 </bean>
  <!-- 配置pojo -->
 <bean id="User" class="com.ssh.pojo.User" scope="prototype"/>
</beans>
时间: 2024-08-03 15:35:39

spring 简单配置的相关文章

spring简单配置

1 <?xml version="1.0" encoding="utf-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/sch

spring注解开发中常用注解以及简单配置

一.spring注解开发中常用注解以及简单配置 1.为什么要用注解开发:spring的核心是Ioc容器和Aop,对于传统的Ioc编程来说我们需要在spring的配置文件中邪大量的bean来向spring容器中注入bean对象, 然而,通过注解编程可以缩短我们开发的时间,简化程序员的代码编写. 2.如何开启注解开发:最常用的方法是使用<mvc:annotation-driven/>来开启注解编程(用一个标签配置了spring注解编程的映射器和适配器,同时配置了许多的参数) 3.如何将有注解的be

spring boot admin 集成的简单配置随笔

和我并肩作战的同事也要相继离职了,心里还是有很多不舍得,现在业务也陆陆续续落在了肩头,上午项目经理让我把spring boot admin集成到现在的项目中,已遍后续的监控. 哇!我哪里搞过这个!心里好慌,好在我面向对象虽然不是很精通,但是面向百度我倒是很拿手,于是开启了,面向百度编程,现在已经成功过了~写个博客继续一下,方便以后使用以及分享. 注:此写法适用于 2.0以下版本 高于2.0请直接官方文档走起:http://codecentric.github.io/spring-boot-adm

springMVC用法 以及一个简单的基于springMVC hibernate spring的配置

替代struts 1  web.xml中配置springmvc中央控制器 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="

Spring Boot 配置优先级顺序

http://www.cnblogs.com/softidea/p/5759180.html 一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一点不同,配置读取可是一个让人有点伤脑筋的问题. Spring Boot提供了一种优先级配置读取的机制来帮助我们从这种困境中走出来. 常规情况下,我们都知道Spring Boot的配置会从application.pro

Maven+Struts+Hibernate+Spring简单项目搭建

这段时间学习如何使用Maven+Struts+Hibernate+Spring注解方式建立项目,在这里感谢孙宇老师.    第一次写博客,主要是方便自己查看,同时分享给大家,希望对大家有所帮助,我也是刚入行的小菜鸟,可能有些地方不对,希望不对的地方,大家可以提出来,共同进步. 项目使用的工具是eclipse,数据库使用的是mysql,项目主要是用注解方式实现三大框架的整合. 首先使用maven建立项目,这里简单介绍一下. 第一步:右击new->other->Maven Project,如下图:

最小可用 Spring MVC 配置

[最小可用 Spring MVC 配置] 1.导入有概率用到的JAR包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/mave

web.xml简单配置

<?xml version="1.0" encoding="UTF-8"?> <!-- 基本表头 --> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation

spring MVC配置详解[转]

现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了.不过要想灵活运用Spring MVC来应对大多数的Web开发,就必须要掌握它的配置及原理. 一.Spring MVC环境搭建:(Spring 2.5.6 + Hibernate 3.2.0) 1. jar包引入 Spring 2.5.6:spring.jar.spring-webmvc.jar.comm