zoukankan      html  css  js  c++  java
  • SSH整合之二:添加Spring环境

    2.添加spring-framework-3.1.1.RELEASE环境:

      1)将下载的spring环境解压后,将dist下面的jar包拷到项目lib文件夹下面。

      2)添加applicationContext.xml文件至项目config下,内容如下:

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <!--
     3   - Middle tier application context definition for the image database.
     4   -->
     5 <beans xmlns="http://www.springframework.org/schema/beans"
     6         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     7         xmlns:context="http://www.springframework.org/schema/context"
     8         xmlns:tx="http://www.springframework.org/schema/tx"
     9         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    10                 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    11                 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    12 
    13     <!-- 自动扫描与装配bean -->
    14     <context:component-scan base-package="cn.clear.web"></context:component-scan>
    15     
    16 </beans>

      3)点击项目名右键---》Build Path ---》Add Libraries ---》选择JUnit ---》点击Next ---》选择JUnit4 ---》Finish。添加了JUnit环境。

      4)在cn.clear.web.test下创建SpringTest.java,具体如下:

     1 package cn.clear.web.test;
     2 
     3 import org.junit.Test;
     4 import org.springframework.context.ApplicationContext;
     5 import org.springframework.context.support.ClassPathXmlApplicationContext;
     6 
     7 public class SpringTest {
     8     
     9     @Test
    10     public void testSpring(){
    11         
    12         ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
    13         
    14         ActionTest actionTest = (ActionTest) ac.getBean("actionTest");
    15         System.out.println(actionTest);
    16     }
    17 }

      5)在ActionTest.java类上添加注解:

      @Controller //控制层注解,在类上添加此注解便于spring管理进行依赖注入。

      @Scope("prototype") //每次对bean的请求都会创建一个新的bean实例。

      6)在SpringTest.java中,选中方法名testSpring右击Runs ---》 JUnit Test,如果结果显示绿条,控制台输出信息,则Spring环境添加成功:

      

      控制台输出:cn.clear.web.test.ActionTest@27b4c1d7

  • 相关阅读:
    'Undefined symbols for architecture i386,clang: error: linker command failed with exit code 1
    The codesign tool requires there only be one 解决办法
    XCode iOS project only shows “My Mac 64bit” but not simulator or device
    Provisioning profile XXXX can't be found 的解决办法
    UIView 中的控件事件穿透 Passthrough 的实现
    Xcode4.5出现时的OC新语法
    xcode 快捷键(持续更新)
    打越狱包
    php缓存与加速分析与汇总
    浏览器的判断
  • 原文地址:https://www.cnblogs.com/clear5/p/4353745.html
Copyright © 2011-2022 走看看