zoukankan      html  css  js  c++  java
  • spring的配置文件和加载

    ①:创建applicationContext.xml配置文件放在src下

    //applicationContext.xml代码
    <?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:util="http://www.springframework.org/schema/util"  
    	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xsi:schemaLocation="
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
    		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
    		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
    		http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
    		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
    <bean id="student" class="entity.Student"  scope="prototype"></bean>
    </beans>
    
    

    ②:导入ioc jar包并创建对应的java类(entity.Studen);

    commons-logging.jar
    spring-beans-版本号.RELEASE.jar
    spring-context-版本号.RELEASE.jar
    spring-core-版本号.RELEASE.jar
    spring-expression-版本号.RELEASE.jar

    ③:加载配置文件创建实例

    String str="applicationContext.xml";
    		ApplicationContext ac=
    			new ClassPathXmlApplicationContext(str);
    		Student s =ac.getBean("student",Student.class);
    
  • 相关阅读:
    Linux 通过sendmail 发邮件到外部邮箱
    基于Ruby的Watir-WebDriver自动化测试方案
    高性能Linux服务器构建实战笔记
    Unix Linux 通用vi命令,使用帮助手册【珍藏版】
    软件测试人员必备Linux命令(初、中、高级)
    网络七层知多少,学以致用
    手机终端高级测试工程师经验总结
    临别前夕,工作总结 于2014年8月13日 终稿
    基于ruby的watir自动化测试 笔记二
    高级软件测试工程师笔试题
  • 原文地址:https://www.cnblogs.com/hts-technology/p/7238202.html
Copyright © 2011-2022 走看看