- Maven和xml配置Spring-IoC环境
- 下载Maven
- idea配置
- 在idea上配置下载的maven
- 创建Maven项目
- 配置pom.xml文件
下载地址https://maven.apache.org
下载最新版本
解压
配置解压文件bin的环境变量
测试环境
doc下输入mvn -v
出现maven版本号则配置成功
配置一下conf文件夹下的settings.xml文件
配置本地的maven仓库
D:repmvn
在mirrors标签里添加maven库国内的镜像源
alimaven central aliyun maven http://maven.aliyun.com/nexus/content/groups/public repo1 central Human Readable Name for this Mirror. http://repo1.maven.org/maven2/ repo2 central Human Readable Name for this Mirror. http://repo2.maven.org/maven2/
profiles标签下配置jdk版本
jdk-1.8 true 1.8 1.8 1.8 1.8
修改后的xml文件
idea配置 在idea上配置下载的mavenD:repmvn alimaven central aliyun maven http://maven.aliyun.com/nexus/content/groups/public repo1 central Human Readable Name for this Mirror. http://repo1.maven.org/maven2/ repo2 central Human Readable Name for this Mirror. http://repo2.maven.org/maven2/ maven-default-http-blocker external:http:* Pseudo repository to mirror external repositories initially using HTTP. http://0.0.0.0/ true jdk-1.8 true 1.8 1.8 1.8 1.8
先去https://mvnrepository.com/地址获取spring-context的jar包位置,通过这个jar包就可以配置其他需要的包
打开这个网址如果出现下面情况
解决方法
1、
2、
3、
就可以了
将这段复制到pom.xml文件中,并且放在dependencies标签里
org.springframework spring-context 5.3.20
如果报红出错
可能需要等一下
测试
结构
beans包
package beans;
public class User {
private Integer id;
private String userName;
private String reralName;
@Override
public String toString() {
return "User{" +
"id=" + id +
", userName='" + userName + ''' +
", reralName='" + reralName + ''' +
'}';
}
}
resources包下创建spring_ioc.xml文件
tests包
package tests;
import beans.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class IoCTest {
@Test
public void test01(){
ApplicationContext ioc = new ClassPathXmlApplicationContext("spring_ioc.xml");
User bean = ioc.getBean("user",User.class);
System.out.println(bean);
}
}
报红
Alt+Ent会自动导入所学要的jar包
运行IoCTest类



