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);
    
  • 相关阅读:
    IIS中使用URL重写工具进行rewrite的规则示例
    施文钧:值得看的文化类节目
    泉州校区/院区分布趋势
    IIS安装SSL证书-轻松实现HTTPS
    [小结]定时任务/作业
    技术或运营的妥协/退让场景
    Windows下开发PHP的准备事项
    移动端之封装个tap()事件
    注解
    Intellij IDEA run coverage之覆盖率测试
  • 原文地址:https://www.cnblogs.com/hts-technology/p/7238202.html
Copyright © 2011-2022 走看看