赞
踩
(点击链接,有spring包下载的方法:
http://blog.csdn.net/sj0613xz/article/details/78714017)
首先,beans.xml中可配置如下:
- <?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:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd">
-
-
-
- <!-- 测试spring的依赖注入 -->
- <bean id="hello" class="java.lang.String">
- <!-- collaborators and configuration for this bean go here -->
- </bean>
-
- <bean id="date" class="java.util.Date">
- <!-- collaborators and configuration for this bean go here -->
- </bean>
-
- <!-- more bean definitions go here -->
-
- </beans>

再建立两个class文件,如下:
- package test;
-
- import java.util.Date;
-
- import javax.annotation.Resource;
-
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-
- /*
- * Spring3.1后多了个spring-test-4.2.4.RELEASE.jar包,这个jar包专门用来支持JUnit基于注解的测试的,该jar包在spring-4.2.4-core中
- * 该jar包里有个SpringJUnit4ClassRunner.class,用@RunWith注解加进来即可
- *
- * 注解@ContextConfiguration表示将ApplicationContext对象注入进来,就不用像以往那样在测试程序里先new了,直接使用
- */
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations="classpath:beans.xml")
- public class Hello {
- @Resource
- private String hello;
-
- @Test //测试Spring IOC的开发环境
- public void printStr() {
- System.out.println(hello);
- }
-
- }

另一个如下所示:
- package test;
-
- import java.util.Date;
-
- import javax.annotation.Resource;
-
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations="classpath:beans.xml")
- public class SSHTest {
-
- @Resource
- private Date date;
-
- @Test //测试Spring IOC的开发环境
- public void springIoc() {
- System.out.println(date);
- }
- }

- drop database if exists shop;
- create database shop default character set utf8;
- use shop;
- drop table if exists category;
- create table category
- (
- /* 类别编号,自动增长 */
- id int not null auto_increment,
- /* 类别名称 */
- type varchar(20),
- /* 类别是否为热点类别,热点类别才有可能显示在首页*/
- hot bool default false,
- /* 设置类别编号为主键*/
- primary key (id)
- );
打开后,我们开始连接到MySQL数据库了,在DB Browser窗口的空白处右键->new,就会弹出下面的对话框:
点击Test Driver,若出现successfully的弹出框,即数据库连接成功。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。