pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.tedu</groupId>
<artifactId>Spring01</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<!-- 设置 JDK 版本为 1.8 -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<!-- 设置编码为 UTF-8 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
<dependencies>
<!-- Spring Context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<!-- 单元测试框架 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
</dependency>
</dependencies>
</project>
spring的主要的类:AnnotationConfigApplicationContext
package cn.tedu.day01;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Test {
public static void main(String[] args) {
// AnnotationConfigApplicationContext 就是Spring
//Annotation: 注解\注释
//Config: 配置
//Application: 缩写app 应用 应用程序
//Context: 上下文 当前情况
//初始化Spring
AnnotationConfigApplicationContext ctx= new AnnotationConfigApplicationContext(Config.class);
//从Spring获取Demo对象!
//ctx 提供了 getBean(类型) 方法, 可以获取Spring创建的对象
Demo demo = ctx.getBean(Demo.class);
System.out.println(demo); //toString() Hello World!
}
}
主要方法:refresh
版权声明:本文为qq_43470725原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。