SpringStudy

- HelloWorld级别的学习
This commit is contained in:
2026-09-21 10:58:27 +08:00
parent 803551339c
commit da42788b84
6 changed files with 65 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
spring管理业务类(Service), dao类(Mapper)
servlet是Servlet容器管理
实体类(Entity)数据载体, 随用随new
抽象类, 接口不允许被管理, 因为不是具体实现, 没法new
+20
View File
@@ -0,0 +1,20 @@
<?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>
<parent>
<groupId>com.linlangjz</groupId>
<artifactId>SpringStudy</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>SpringFramework</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,14 @@
package com.ycjy;
import com.ycjy.entity.User;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
User myUser = context.getBean("myUser", User.class);
System.out.println("code:" + myUser.hashCode());
System.out.println(myUser);
System.out.println("code:" + myUser.hashCode());
}
}
@@ -0,0 +1,5 @@
package com.ycjy.entity;
public class User {
}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="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">
<!-- scope: 作用域 prototype: 每次获取时都会创建一个新的实例 -->
<bean id="myUser" class="com.ycjy.entity.User" scope="prototype"/>
</beans>
+14
View File
@@ -7,11 +7,25 @@
<groupId>com.linlangjz</groupId>
<artifactId>SpringStudy</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>SpringFramework</module>
</modules>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-context.version>7.0.9</spring-context.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-context.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>