Spring

Inversion of ControlAOP(Aspect Oriented Programming)面向切面编程
一、导入maven依赖 org.springframework spring-webmvc 5.1.10.RELEASE
二、编写实体类

  1. publicclassHello{
  2. privateStringname;
  3. publicStringgetName(){
  4. returnname;
  5. }
  6. publicvoidsetName(Stringname){
  7. this.name=name;
  8. }
  9. publicvoidshow(){
  10. System.out.println(“Hello,”+name);
  11. }
  12. }
  13. <?xmlversion=”1.0”encoding=”UTF-8”?>
  14. <beansxmlns=”http://www.springframework.org/schema/beans
  15. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance
  16. xsi:schemaLocation=”http://www.springframework.org/schema/beans
  17. http://www.springframework.org/schema/beans/spring-beans.xsd“>

  18. @Test
  19. publicvoidtest(){
  20. //解析beans.xml文件 , 生成管理相应的Bean对象
  21. ApplicationContextcontext=newClassPathXmlApplicationContext(“beans.xml”);
  22. //getBean : 参数即为spring配置文件中bean的id .
  23. Hellohello=(Hello)context.getBean(“hello”);
  24. hello.show();
  25. }
    1、无参构造器

    2、有参构造器三种方法