zoukankan      html  css  js  c++  java
  • spring来了-02-HelloWorld

    spring的各个版本说明:

      在3.0以下的版本,源码有spring中相关的所有包[spring功能+依赖包],如:2.5版本

      在3.0以上的版本,源码中只有spring的核心功能包[没有依赖包],如果要用依赖包,需要单独下载!

    1. 在spring-framework-3.2.5.RELEASE中,
      • 核心的5个jar包,必需的
        • commons-logging-1.1.3.jar               日志(依赖包)
        • spring-beans-3.2.5.RELEASE.jar        bean节点
        • spring-context-3.2.5.RELEASE.jar      spring上下文节点
        • spring-core-3.2.5.RELEASE.jar       spring核心功能
        • spring-expression-3.2.5.RELEASE.jar  spring表达式相关
    2. 核心配置文件:applicationContext.xml,也可以为bean.xml
       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"
       4     xmlns:p="http://www.springframework.org/schema/p"
       5     xmlns:context="http://www.springframework.org/schema/context"
       6     xmlns:aop="http://www.springframework.org/schema/aop"
       7     xmlns:tx="http://www.springframework.org/schema/tx"
       8     xsi:schemaLocation="
       9         http://www.springframework.org/schema/beans
      10         http://www.springframework.org/schema/beans/spring-beans.xsd
      11         http://www.springframework.org/schema/context
      12         http://www.springframework.org/schema/context/spring-context.xsd
      13         http://www.springframework.org/schema/aop
      14         http://www.springframework.org/schema/aop/spring-aop.xsd
      15         http://www.springframework.org/schema/tx
      16          http://www.springframework.org/schema/tx/spring-tx.xsd">
      17 
      18     <bean id="user" class="cn.fuyi.a_helloworld.User"></bean>
      19 </beans>
    3. 测试
       1 public class App {
       2 
       3     @Test
       4     public void testIOC() {
       5         Resource resource = new ClassPathResource("cn/fuyi/a_helloworld/ApplicationContext.xml");
       6         BeanFactory factory = new XmlBeanFactory(resource);
       7         
       8         User user = (User) factory.getBean("user");
       9         System.out.println(user);
      10     }
      11     
      12     
      13     @Test
      14     public void testAc() throws Exception {
      15         ApplicationContext ac = new ClassPathXmlApplicationContext("cn/fuyi/a_helloworld/ApplicationContext.xml");
      16         
      17         User user = (User)ac.getBean("user");
      18         System.out.println(user);
      19     }
      20 
      21 }
  • 相关阅读:
    pat甲级 1155 Heap Paths (30 分)
    pat甲级 1152 Google Recruitment (20 分)
    蓝桥杯 基础练习 特殊回文数
    蓝桥杯 基础练习 十进制转十六进制
    蓝桥杯 基础练习 十六进制转十进制
    蓝桥杯 基础练习 十六进制转八进制
    51nod 1347 旋转字符串
    蓝桥杯 入门训练 圆的面积
    蓝桥杯 入门训练 Fibonacci数列
    链表相关
  • 原文地址:https://www.cnblogs.com/fuyiming/p/5824484.html
Copyright © 2011-2022 走看看