zoukankan      html  css  js  c++  java
  • spring 学习

    一、使用xml 生成bean

    <?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: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/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
        <!--扫描service包-->
        <context:component-scan base-package="com.java.SimpleFactory"></context:component-scan>
        <!--创建dbcp数据源连接池-->
    
        <!--创建mybatis的SqlSessionFactory工厂类对象-->
    
        <!--配置扫描mybatis的dao接口 ,会为dao接口创建myabtis的dao接口实现类对象,放置到session工厂中-->
    
        <!--声明spring 的事物管理器对象-->
    
        <!--声明以注解的方式配置spring 的事物-->
        <!--引入spring 和shiro集成的主配置文件-->
    
    </beans>

    二、测试类

    public class test {
    
        @Autowired
        Man man;
        public static void main(String[] args) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
    
         /*   Animal animal=(Animal) BeanFactory.getBean("man");
            animal.say();
            Animal animal2=(Animal) BeanFactory.getBean("man");
            animal2.say();
           *//* Car car=(Car) BeanFactory.getBean("care");
            car.run();*//*
            System.out.println(animal==animal2);*/
            ApplicationContext ctx = new FileSystemXmlApplicationContext("filename.xml");
    
            Animal animal2=(Animal) ctx.getBean("man");
            Animal animal3=(Animal) ctx.getBean("man");
            animal2.say();
            System.out.println(ctx);
    
        }
  • 相关阅读:
    Ubuntu-12.04.5 安装 oracle 12.2.0.1 数据库database软件
    Ubuntu-12.04.5 再再再次安装 oracle 11.2.0.4 数据库database软件(又不一样了!)
    Ubuntu-4.10 安装 oracle 11.2.0.4 数据库database软件(最古老的ubuntu)
    PATH add
    可望不可即 可望不可及
    天干地支
    24节气
    二进制、十进制和十六进制转换器
    信用卡三磁道
    ISO8583
  • 原文地址:https://www.cnblogs.com/lufei33180/p/13337899.html
Copyright © 2011-2022 走看看