首页 > 编程语言 > 详细

spring 学习

时间:2020-07-19 00:29:36      阅读:51      评论:0      收藏:0      [点我收藏+]

一、使用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);

    }

 

spring 学习

原文:https://www.cnblogs.com/lufei33180/p/13337899.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!