• 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);
    
  • 相关阅读:
    Apache HTTP Server 与 Tomcat 的三种连接方式介绍
    Java使用Memcached
    缓存系统MemCached的Java客户端优化历程
    在Java中使用Memcached(转)
    memcached简介及java使用方法
    JS中冒泡排序,选择排序,快速排序
    DOM的查找,新增,删除操作
    JS中文档碎片的理解和使用
    JS中undefined和null的区别,以及出现原因
    JS中的数学方法
  • 原文地址:https://www.cnblogs.com/hts-technology/p/7238202.html
Copyright © 2020-2023  润新知