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);
    
        }
  • 相关阅读:
    Warning! PATH is not properly set up...
    用rvm切换ruby
    Mac下多版本JDK安装
    iOS开发 密码里面含有特殊字符如何处理传给后端
    Cornerstone版本回退160013错误
    iOS 11 Xcode9 tableview点击cell上的按钮cell自动往上跳动
    iOS 获取全部字体的Fontfamily和FontName
    iOS WKWebView 点击超链接跳转至Safari
    iOS 11在window上加视图不显示
    Java并发(2)
  • 原文地址:https://www.cnblogs.com/lufei33180/p/13337899.html
Copyright © 2011-2022 走看看