===========================================================================
pom.xml依赖如下:
<?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”>
4.0.0
org.jsy
learn-spring
1.0-SNAPSHOT
org.springframework
spring-core
5.2.9.RELEASE
org.springframework
spring-context
5.2.9.RELEASE
junit
junit
4.13
test
- 项目结构

==================================================================
package com.jsy.pojo;
public class User {
String name;
public User() {
}
public User(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return “我是”+this.name;
}
}
import com.jsy.pojo.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestUser {
@Test
public void test(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(“beans.xml”);
User user = (User)applicationContext.getBean(“user”);
System.out.println(user);
}
}
- XML配置
<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
https://www.springframework.org/schema/beans/spring-beans.xsd">
- 一个坑点
上面这种注入是依赖于P注入,在这种情况下,必须有无参构造器!
最后
小编这些年深知大多数初中级工程师,想要提升自己,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此我收集整理了一份《2024年Java全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你需要这些资料,⬅专栏获取
自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**
[外链图片转存中…(img-dKh6gIWx-1719684584319)]
[外链图片转存中…(img-qBiZoIii-1719684584320)]
[外链图片转存中…(img-DLRVtP4i-1719684584321)]
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你需要这些资料,⬅专栏获取