<?xml version="1.0" encoding="UTF-8"?>
<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-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.jdbc.sqlserver.SQLServerDriver">
</property>
<property name="url"
value="jdbc:microsoft:sqlserver://localhost:1433">
</property>
<property name="username" value="sa"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/qingshow/po/Users.hbm.xml</value></list>
</property></bean>
<!-- 配置DAO组件 ////////////////////////////////////////////////////////-->
<!-- 登录管理 -->
<bean id="loginDAO" class="com.qingshow.dao.LoginDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 配置service业务组件 /////////////////////////////////////////////////// -->
<bean id="loginService" class="com.qingshow.service.LoginServiceImpl">
<property name="loginDAO">
<ref local="loginDAO"/>
</property>
</bean>
<!-- 配置Action组件 ///////////////////////////////////////////////////-->
<bean name="/login" class="com.qingshow.web.action.LoginAction">
<property name="loginService">
<ref local="loginService"/>
</property>
</bean>
</beans>
6.测试。在com.qingshow.test下新建LoginTest类,运行ok.代码如下
1 package com.qingshow.test;
2
3 import org.springframework.context.ApplicationContext;
4 import org.springframework.context.support.FileSystemXmlApplicationContext;
5
6 import com.qingshow.po.Users;
7 import com.qingshow.service.LoginService;
8
9 public class LoginTest {
10
11 public static void main(String[] args) {
12
13 ApplicationContext context = new FileSystemXmlApplicationContext(
14 "src/applicationContext.xml");
15 LoginService loginService = (LoginService) context
16 .getBean("loginService");
17 Users user=new Users();
18
19 boolean b=false;
20 b=loginService.login("青秀","qingshow"); //可以测试一下中文是否有乱码
21
22 if (b) {
23 System.out.println("ok");
24 } else {
25 System.out.println("error");
26 }
27 }
28 }
29