• Spring------约束导入和application.xml的引入方式


    1.spring约束的导入

     

    2.SSH常用约束

     

     

     

     

    3.application.xml的引入方式

      <1.通过ClassPathXmlApplicationContext引入配置文件application.xml

     

    public void fun1() {
    
            // 1.创建容器对象 ApplicationContext容器创建时自动创建所有对象
            ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
            // 2.向容器要user对象
            User u = (User) ac.getBean("user1");
            // 3.打印user对象
            System.out.println(u);
    
        }

     

     

      <2.application.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.springframework.org/schema/beans"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd ">
    
        <!--将user对象交给spring容器管理 -->
    
        <!--bean元素:使用该元素描述需要spring容器管理的对象 
            name:元素给被管理的对象起一个名字。获得对象时通过该名称获得对象 
            class属性:被管理对象的完整类名
          -->
        <!-- 创建方式一:空参构造 -->
        <bean name="user1" class="com.hdh.a_bean.User" scope="singleton"></bean>
    </beans>

     

      <3.命名空间的引入

     

     

    4.在过滤器中配置application.xml。application.xml随项目的启动而启动(推荐使用)

        <!--配置spring配置文件位置参数 -->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </context-param>

     

     

     

     

     

     

     

     

  • 相关阅读:
    Android 与 JavaScript 相互调用
    Possible causes are invalid address of the remote server or browser start-up failure.
    pythonCharm 破解
    IntelliJ IDE破解
    JetBrains
    Fidder
    Monkey
    ScrollView fillViewport
    2020牛客寒假算法基础集训营5 E Enjoy the game
    2020牛客寒假算法基础集训营4 H 坐火车
  • 原文地址:https://www.cnblogs.com/asndxj/p/10568842.html
Copyright © 2020-2023  润新知