Spring
Inversion of ControlAOP(Aspect Oriented Programming)面向切面编程
一、导入maven依赖
二、编写实体类
- publicclassHello{
- privateStringname;
- publicStringgetName(){
- returnname;
- }
- publicvoidsetName(Stringname){
- this.name=name;
- }
- publicvoidshow(){
- System.out.println(“Hello,”+name);
- }
- }
- <?xmlversion=”1.0”encoding=”UTF-8”?>
- <beansxmlns=”http://www.springframework.org/schema/beans“
- xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“
- xsi:schemaLocation=”http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd“>
-
- @Test
- publicvoidtest(){
- //解析beans.xml文件 , 生成管理相应的Bean对象
- ApplicationContextcontext=newClassPathXmlApplicationContext(“beans.xml”);
- //getBean : 参数即为spring配置文件中bean的id .
- Hellohello=(Hello)context.getBean(“hello”);
- hello.show();
- }
1、无参构造器
2、有参构造器三种方法