ssh搭建

1.第一步:spring测试

   新建一个Web 工程后,导入所需jar在lib文件里。在src 文件下新建Spring配置文件,applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- 新加入spring xsd  可在spring 包指导手册里找到对应的内容-->
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:aop="http://www.springframework.org/schema/aop"   
    xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans   
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd  
    http://www.springframework.org/schema/context   
    http://www.springframework.org/schema/context/spring-context-3.2.xsd  
    http://www.springframework.org/schema/aop  
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd  
    http://www.springframework.org/schema/tx  
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
    
    <!--    测试springioc -->
    <bean id = "date" class = "java.util.Date">
    
    </bean>
    
</beans> 

新建一个test类文件。保证引入JUnit库,TestSpring 

package com.zdy.testspring;

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;
/**
 * @author 翟德有
 * @date : 2016年10月30日 上午12:09:39
 */ 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext.xml")
public class TestSpring {
    @Resource
    private Date date;
    @Test
    public void test() {
        System.out.println("你好"+date);
    }

}

点击类方法  test(), run as ->JUnit test 执行后,Console出现如下结果

你好Sat Oct 29 23:11:26 CST 2016

注意:如果出现结果

log4j:WARN No appenders could be found for logger (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.
你好Sun Oct 30 00:14:26 CST 2016

则是缺少 log4j.properties 文件添加在src 目录下即可。注意:log4j.properties可修改

# Configure logging for testing: optionally with log file
#log4j.rootLogger=Wan, stdout
log4j.rootLogger=INFO, stdout, logfile

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=d:\\spring.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

 

posted @ 2016-10-30 00:29  逸足天涯  阅读(231)  评论(0编辑  收藏  举报