• spring01


            目录

            一,对于spring的理解

            二,spring中ioc的特点

                 2.1 控制反转

                 2.2 注入依赖

                       方式1:set注入.

                       方式2:构造注入

                       方式3:自动装配

            三,spring与web容器的整合


     一、对spring的理解

    spring是一个开源框架,它由Rod Johnson 创建。它是为了解决企业应用开发的复杂性而创建的。

    目的:解决企业应用开发的复杂性

    功能:使用基本的JavaBean代替EJB,并提供了更多的企业应用功能

    范围:任何Java应用

    简单来说,Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架。

    二、spring中ioc的特点

    建一个maven项目

    修改pom.xml与web.xml

    pom.xml

    1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    3. <modelVersion>4.0.0modelVersion>
    4. <groupId>com.cdlgroupId>
    5. <artifactId>T280_springartifactId>
    6. <packaging>warpackaging>
    7. <version>0.0.1-SNAPSHOTversion>
    8. <name>T280_spring Maven Webappname>
    9. <url>http://maven.apache.orgurl>
    10. <properties>
    11. <spring.version>5.0.1.RELEASEspring.version>
    12. <javax.servlet.version>4.0.0javax.servlet.version>
    13. <junit.version>4.12junit.version>
    14. properties>
    15. <dependencies>
    16. <dependency>
    17. <groupId>junitgroupId>
    18. <artifactId>junitartifactId>
    19. <version>3.8.1version>
    20. <scope>testscope>
    21. dependency>
    22. <dependency>
    23. <groupId>org.springframeworkgroupId>
    24. <artifactId>spring-contextartifactId>
    25. <version>${spring.version}version>
    26. dependency>
    27. <dependency>
    28. <groupId>org.springframeworkgroupId>
    29. <artifactId>spring-aspectsartifactId>
    30. <version>${spring.version}version>
    31. dependency>
    32. <dependency>
    33. <groupId>junitgroupId>
    34. <artifactId>junitartifactId>
    35. <version>${junit.version}version>
    36. <scope>testscope>
    37. dependency>
    38. <dependency>
    39. <groupId>javax.servletgroupId>
    40. <artifactId>javax.servlet-apiartifactId>
    41. <version>${javax.servlet.version}version>
    42. <scope>providedscope>
    43. dependency>
    44. dependencies>
    45. <build>
    46. <finalName>T280_springfinalName>
    47. <plugins>
    48. <plugin>
    49. <groupId>org.apache.maven.pluginsgroupId>
    50. <artifactId>maven-compiler-pluginartifactId>
    51. <version>3.7.0version>
    52. <configuration>
    53. <source>1.8source>
    54. <target>1.8target>
    55. <encoding>UTF-8encoding>
    56. configuration>
    57. plugin>
    58. plugins>
    59. build>
    60. project>

    2.1控制反转

    建一个com.ljj.biz的包

    UserBiz

    1. package com.ljj.biz;
    2. public interface UserBiz {
    3. void list();
    4. }

    web.xml

    1. package com.ljj.biz;
    2. public interface UserBiz {
    3. void list();
    4. }
    1. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    4. version="3.1">
    5. <display-name>Archetype Created Web Applicationdisplay-name>
    6. web-app>

    建一个com.ljj.biz.impl的包

    UserBizImpl1

    1. package com.ljj.biz.impl;
    2. import com.ljj.biz.UserBiz;
    3. public class UserBizImpl1 implements UserBiz {
    4. @Override
    5. public void list() {
    6. System.out.println("查询用户数据 按照年龄排序。。。");
    7. }
    8. }

    UserBizImpl2

    1. package com.ljj.biz.impl;
    2. import com.ljj.biz.UserBiz;
    3. public class UserBizImpl2 implements UserBiz {
    4. @Override
    5. public void list() {
    6. System.out.println("查询用户数据 按照入职时间排序。。。");
    7. }
    8. }

    建一个com.ljj.web的包

    OrderAction

    1. package com.ljj.web;
    2. import com.ljj.biz.UserBiz;
    3. import com.ljj.biz.impl.UserBizImpl1;
    4. public class OrderAction {
    5. private UserBiz userBiz = new UserBizImpl1();
    6. public void list() {
    7. userBiz.list();
    8. }
    9. }

    UserAction

    1. package com.cdl.web;
    2. import com.ljj.biz.UserBiz;
    3. import com.ljj.biz.impl.UserBizImpl1;
    4. public class UserAction {
    5. private UserBiz userBiz = new UserBizImpl1();
    6. public void list() {
    7. userBiz.list();
    8. }
    9. }

     常规做法即运用spring之前的处理方法

     需求:
     同时在用户模块,订单模块拿到所有的用户数据
      
      需求变更1:
      同时在用户模块,订单模块拿到所有的用户数据,并且要求用户数据是通过年龄排序的
      对应策略:修改UserBiz中list方法,添加排序功能
      
     需求变更2:
     同时在用户模块,订单模块拿到所有的用户数据,并且要求用户数据是通过注册时间排序的
     对应策略,修改UserBiz中list方法,添加排序功能,按照时间点排序

     总结:
     最原始:频繁修改业务层biz的代码
     多实现:凡是涉及到用户业务层调用的地方,都需要修改代码

     使用spring处理

    先加入spring的配置文件

    spring-context.xml

    1. "1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:aop="http://www.springframework.org/schema/aop"
    5. xmlns:context="http://www.springframework.org/schema/context"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
    9. beans>

    注意:一定要在有网络的情况下进行,否则约束不生效

    IOC的主要作用管理整个项目的Javabean:依靠依赖注入、控制反转的特点进行管理

    spring-context.xml

    1. "1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:aop="http://www.springframework.org/schema/aop"
    5. xmlns:context="http://www.springframework.org/schema/context"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
    9. <bean class="com.ljj.biz.impl.UserBizImpl2" id="userBiz2">bean>
    10. <bean class="com.ljj.web.UserAction" id="userAction">
    11. <property name="userBiz" ref="userBiz2">property>
    12. bean>
    13. <bean class="com.ljj.web.OrderAction" id="orderAction">bean>
    14. beans>

     UserAction

    1. package com.ljj.web;
    2. import com.ljj.biz.UserBiz;
    3. import com.ljj.biz.impl.UserBizImpl1;
    4. public class UserAction {
    5. //private UserBiz userBiz = new UserBizImpl1();
    6. private UserBiz userBiz;
    7. public void list() {
    8. userBiz.list();
    9. }
    10. public UserBiz getUserBiz() {
    11. return userBiz;
    12. }
    13. public void setUserBiz(UserBiz userBiz) {
    14. this.userBiz = userBiz;
    15. }
    16. }

     建一个com.cdl.ioc的包

    在里面建一个Demo1的类

    建模,打印com.ljj.biz.impl.UserBizImpl2中的语句

    1. package com.ljj.ioc;
    2. import org.springframework.context.support.ClassPathXmlApplicationContext;
    3. import com.ljj.web.UserAction;
    4. public class Demo1 {
    5. @SuppressWarnings("resource")
    6. public static void main(String[] args) {
    7. //建模
    8. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/spring-context.xml");
    9. UserAction userAction = (UserAction) context.getBean("userAction");
    10. userAction.list();
    11. }
    12. }

      运行结果:

    9e234c4879fd44ea8aad8ba93d1402e9.png

     总结:

    1.对spring框架的配置文件进行建模,建模之后spring-context.xml中所有的Javabean信息
     都会加载进spring容器的上下文中
     2.上下文中就包含了spring-context.xml 所有对象

    测试orderaction也拿到相同结果,配置和orderaction都如useraction一致修改

    1. package com.ljj.web;
    2. import com.ljj.biz.UserBiz;
    3. import com.ljj.biz.impl.UserBizImpl1;
    4. public class OrderAction {
    5. //private UserBiz userBiz = new UserBizImpl1();
    6. private UserBiz userBiz;
    7. public void list() {
    8. userBiz.list();
    9. }
    10. public UserBiz getUserBiz() {
    11. return userBiz;
    12. }
    13. public void setUserBiz(UserBiz userBiz) {
    14. this.userBiz = userBiz;
    15. }
    16. }
    1. "1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:aop="http://www.springframework.org/schema/aop"
    5. xmlns:context="http://www.springframework.org/schema/context"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
    9. <bean class="com.ljj.biz.impl.UserBizImpl2" id="userBiz2">bean>
    10. <bean class="com.ljj.web.UserAction" id="userAction">
    11. <property name="userBiz" ref="userBiz2">property>
    12. bean>
    13. <bean class="com.ljj.web.OrderAction" id="orderAction">
    14. <property name="userBiz" ref="userBiz2">property>
    15. bean>
    16. beans>

    结果:

    47bd52be5b21408faf0b56fb344c6ce6.png

     若是要按年龄排序,就只需要修改配置文件就OK了

    1. "1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:aop="http://www.springframework.org/schema/aop"
    5. xmlns:context="http://www.springframework.org/schema/context"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
    9. <bean class="com.ljj.biz.impl.UserBizImpl1" id="userBiz2">bean>
    10. <bean class="com.ljj.web.UserAction" id="userAction">
    11. <property name="userBiz" ref="userBiz2">property>
    12. bean>
    13. <bean class="com.ljj.web.OrderAction" id="orderAction">
    14. <property name="userBiz" ref="userBiz2">property>
    15. bean>
    16. beans>

     结果:

    608637791a104c2fab0dfb61b022c11d.png

     若是要按年龄排序,就只需要修改配置文件就OK了

    1. "1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:aop="http://www.springframework.org/schema/aop"
    5. xmlns:context="http://www.springframework.org/schema/context"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
    9. <bean class="com.ljj.biz.impl.UserBizImpl1" id="userBiz2">bean>
    10. <bean class="com.ljj.web.UserAction" id="userAction">
    11. <property name="userBiz" ref="userBiz2">property>
    12. bean>
    13. <bean class="com.ljj.web.OrderAction" id="orderAction">
    14. <property name="userBiz" ref="userBiz2">property>
    15. bean>
    16. beans>

    ec45517e6882461193803ead342c9664.png

     结论:IOC特点(控制反转):将创建对象的权利反转给spring容器来完成

     2.2注入依赖

    方式① set注入

    1517bd1a5b9345bba07ff2c69782bedc.png

    87f4168514ab40f69c2d053c8cf5441c.png

     可见的报错原因是找不到set的方法

    接下来用一个例子(多注入三个属性)来更深入的了解

    UserAction

    1. package com.ljj.web;
    2. import java.util.List;
    3. import com.ljj.biz.UserBiz;
    4. import com.ljj.biz.impl.UserBizImpl1;
    5. public class UserAction {
    6. //private UserBiz userBiz = new UserBizImpl1();
    7. private UserBiz userBiz;
    8. public UserBiz getUserBiz() {
    9. return userBiz;
    10. }
    11. public void setUserBiz(UserBiz userBiz) {
    12. this.userBiz = userBiz;
    13. }
    14. private String name;
    15. private int age;
    16. private List hobby;
    17. public String getName() {
    18. return name;
    19. }
    20. public void setName(String name) {
    21. this.name = name;
    22. }
    23. public int getAge() {
    24. return age;
    25. }
    26. public void setAge(int age) {
    27. this.age = age;
    28. }
    29. public List getHobby() {
    30. return hobby;
    31. }
    32. public void setHobby(List hobby) {
    33. this.hobby = hobby;
    34. }
    35. public void list() {
    36. System.out.println(name);
    37. System.out.println(age);
    38. System.out.println(hobby);
    39. userBiz.list();
    40. }
    41. }
    1. "1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:aop="http://www.springframework.org/schema/aop"
    5. xmlns:context="http://www.springframework.org/schema/context"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
    9. <bean class="com.ljj.biz.impl.UserBizImpl1" id="userBiz2">bean>
    10. <bean class="com.ljj.web.UserAction" id="userAction">
    11. <property name="userBiz" ref="userBiz2">property>
    12. <property name="age" value="22">property>
    13. <property name="hobby">
    14. <list>
    15. <value>篮球value>
    16. <value>足球value>
    17. <value>唱歌value>
    18. list>
    19. property>
    20. bean>
    21. <bean class="com.ljj.web.OrderAction" id="orderAction">
    22. <property name="userBiz" ref="userBiz2">property>
    23. bean>
    24. beans>
    1. package com.ljj.ioc;
    2. import org.springframework.context.support.ClassPathXmlApplicationContext;
    3. import com.ljj.web.OrderAction;
    4. import com.ljj.web.UserAction;
    5. /**
    6. * 1.对spring框架的配置文件进行建模,建模之后spring-context.xml中所有的Javabean信息
    7. * 都会加载进spring容器的上下文中
    8. * 2.上下文中就包含了spring-context.xml 所有对象
    9. * @author Lenovo
    10. *
    11. * IOC特点(控制反转):将创建对象的权利反转给spring容器来完成
    12. *
    13. *
    14. */
    15. public class Demo1 {
    16. @SuppressWarnings("resource")
    17. public static void main(String[] args) {
    18. //建模
    19. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/spring-context.xml");
    20. UserAction userAction = (UserAction) context.getBean("userAction");
    21. userAction.list();
    22. OrderAction orderAction = (OrderAction) context.getBean("orderAction");
    23. orderAction.list();
    24. }
    25. }

    结果:

    a9d6fdbfef164c989ad654f21b7ec2b7.png

     方式② 构造注入

    OrderAction

    1. package com.ljj.web;
    2. import java.util.List;
    3. import com.ljj.biz.UserBiz;
    4. import com.ljj.biz.impl.UserBizImpl1;
    5. /**
    6. * 依赖注入的三种方式:
    7. * 1.set注入
    8. * 2.构造注入
    9. * 3.自动装配
    10. * byName
    11. * byType
    12. * @author Lenovo
    13. *
    14. */
    15. public class OrderAction {
    16. //private UserBiz userBiz = new UserBizImpl1();
    17. private UserBiz userBiz;
    18. public UserBiz getUserBiz() {
    19. return userBiz;
    20. }
    21. public void setUserBiz(UserBiz userBiz) {
    22. this.userBiz = userBiz;
    23. }
    24. private String name;
    25. private int age;
    26. private List hobby;
    27. public OrderAction(String name, int age, List hobby) {
    28. super();
    29. this.name = name;
    30. this.age = age;
    31. this.hobby = hobby;
    32. }
    33. public OrderAction() {
    34. super();
    35. // TODO Auto-generated constructor stub
    36. }
    37. public void list() {
    38. System.out.println(name);
    39. System.out.println(age);
    40. System.out.println(hobby);
    41. userBiz.list();
    42. }
    43. }
    1. "1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:aop="http://www.springframework.org/schema/aop"
    5. xmlns:context="http://www.springframework.org/schema/context"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
    9. <bean class="com.ljj.biz.impl.UserBizImpl1" id="userBiz2">bean>
    10. <bean class="com.ljj.web.UserAction" id="userAction">
    11. <property name="userBiz" ref="userBiz2">property>
    12. <property name="age" value="22">property>
    13. <property name="name" value="cdl">property>
    14. <property name="hobby">
    15. <list>
    16. <value>篮球value>
    17. <value>足球value>
    18. <value>唱歌value>
    19. list>
    20. property>
    21. bean>
    22. <bean class="com.ljj.web.OrderAction" id="orderAction">
    23. <property name="userBiz" ref="userBiz2">property>
    24. <constructor-arg name="age" value="23">constructor-arg>
    25. <constructor-arg name="hobby">
    26. <list>
    27. <value>篮球1value>
    28. <value>足球1value>
    29. <value>唱歌1value>
    30. list>
    31. constructor-arg>
    32. bean>
    33. beans>

    结果:

    300d3067555c4dc0a91cf6bb6fe65854.png

     方式③ 自动装配

    将set和构造的注入 注释

    byType不报错 byName报错

    064f56605b6c4d89afce48a505950822.png

     结果:e169187e09c144f69c91a2df7942b852.png

     byName:

    2ff76ac3271c47ac80ba629a9c306c46.pngce164ac51ce7423d94e8c43db4ce9f98.png

     总结:

     自动装配
     default-autowire="byName" 
    byName:是通过spring管理的bean对象的ID进行查找,如果找不到,则注入失败,反之成功
     byType:是通过spring管理的bean对象的接口实现类进行查找,如果没有或者2个以上,则注入失败,反之成功

     三、spring与web容器的整合

    分析:

    spring与web容器的整合原理
        why:建模的过程是十分耗时的
      解决问题:
     1.建模必不可少
     2.建模只保障只执行一次
     3.建模后期望在每一个servlet都能够拿到spring的上下文对象ClassPathXmlApplicationContext
      how:
      1.监听器的初始化方法 只执行一次
      2.spring的上下文要存放在Tomcat上下文中

    建一个包com.cdl.ioc.listener

    1. package com.ljj.ioc.listener;
    2. import javax.servlet.ServletContext;
    3. import javax.servlet.ServletContextEvent;
    4. import javax.servlet.ServletContextListener;
    5. import org.springframework.context.support.ClassPathXmlApplicationContext;
    6. public class SpringLoadListener implements ServletContextListener{
    7. @Override
    8. public void contextInitialized(ServletContextEvent sce) {
    9. System.out.println("初始化执行");
    10. ServletContext servletContext = sce.getServletContext();
    11. String springConfigLocation = servletContext.getInitParameter("springConfigLocation");
    12. System.out.println(springConfigLocation+"...");
    13. //拿到spring上下文
    14. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/spring-context.xml");
    15. //将spring的上下文保存在Tomcat上下文中
    16. servletContext.setAttribute("springContext", context);
    17. }
    18. }

    在com.cdl.ioc中建一个类DemoServlet

    1. package com.ljj.ioc;
    2. import java.io.IOException;
    3. import javax.servlet.ServletException;
    4. import javax.servlet.annotation.WebServlet;
    5. import javax.servlet.http.HttpServlet;
    6. import javax.servlet.http.HttpServletRequest;
    7. import javax.servlet.http.HttpServletResponse;
    8. import org.springframework.context.support.ClassPathXmlApplicationContext;
    9. import com.ljj.web.UserAction;
    10. /**
    11. * spring与web容器的整合原理
    12. * why:建模的过程是十分耗时的
    13. * 解决问题:
    14. * 1.建模必不可少
    15. * 2.建模只保障只执行一次
    16. * 3.建模后期望在每一个servlet都能够拿到spring的上下文对象ClassPathXmlApplicationContext
    17. * how:
    18. * 1.监听器的初始化方法 只执行一次
    19. * 2.spring的上下文要存放在Tomcat上下文中
    20. * @author Lenovo
    21. *
    22. */
    23. @WebServlet("/springDemo")
    24. public class DemoServlet extends HttpServlet{
    25. @Override
    26. protected void service(HttpServletRequest arg0, HttpServletResponse arg1){
    27. //ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/spring-context.xml");
    28. ClassPathXmlApplicationContext context = (ClassPathXmlApplicationContext) arg0.getServletContext().getAttribute("springContext");
    29. UserAction userAction = (UserAction) context.getBean("userAction");
    30. userAction.list();
    31. }
    32. }

    spring-context.xml

    1. "1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:aop="http://www.springframework.org/schema/aop"
    5. xmlns:context="http://www.springframework.org/schema/context"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
    9. <bean class="com.ljj.biz.impl.UserBizImpl1" id="userBiz">bean>
    10. <bean class="com.ljj.biz.impl.UserBizImpl1" id="userBiz1">bean>
    11. <bean class="com.ljj.web.UserAction" id="userAction">
    12. <property name="userBiz" ref="userBiz1">property>
    13. <property name="age" value="22">property>
    14. <property name="name" value="cdl">property>
    15. <property name="hobby">
    16. <list>
    17. <value>篮球value>
    18. <value>足球value>
    19. <value>唱歌value>
    20. list>
    21. property>
    22. bean>
    23. <bean class="com.ljj.web.OrderAction" id="orderAction">
    24. <property name="userBiz" ref="userBiz1">property>
    25. <constructor-arg name="name" value="cdl">constructor-arg>
    26. <constructor-arg name="age" value="23">constructor-arg>
    27. <constructor-arg name="hobby">
    28. <list>
    29. <value>篮球1value>
    30. <value>足球1value>
    31. <value>唱歌1value>
    32. list>
    33. constructor-arg>
    34. bean>
    35. beans>

    web.xml

    1. "http://xmlns.jcp.org/xml/ns/javaee"
    2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    4. version="3.1">
    5. <display-name>Archetype Created Web Applicationdisplay-name>
    6. <context-param>
    7. <param-name>springConfigLocationparam-name>
    8. <param-value>/applicationContext.xmlparam-value>
    9. context-param>
    10. <listener>
    11. <listener-class>com.ljj.ioc.listener.SpringLoadListenerlistener-class>
    12. listener>

    结果:得到了路径(成功)

    33b190452acb40ba9ddf4d20e4ff5824.png

     d9ff6efb0ddb41feaa0eeee93a8d19d5.png

     

     

     

  • 相关阅读:
    使用JS简单实现一下apply、call和bind方法
    AcWing-1-递归实现指数型枚举
    接口与抽象类的相同与不同
    Apache Shiro反序列化攻击技术剖析与防护研判分析
    【C语言】数组的强化训练(详细讲解+源码展示)
    红黑树、、、
    【代码精读】optee的RPC机制
    【C语言刷LeetCode】1004. 最大连续1的个数 III(M)
    OpenHarmony3.1 Release版本特性解析——硬件资源池化架构介绍
    反射的机制
  • 原文地址:https://blog.csdn.net/weixin_64313980/article/details/126182050