1、父工程pom.xml
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"> <modelVersion>4.0.0</modelVersion> <groupId>com.atguigu</groupId> <artifactId>pro-ssm</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>pro04-spring-ioc-xml</module> </modules> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring.version>6.0.6</spring.version> <junit.version>5.3.1</junit.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> </project>
2、子工程pom.xml
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"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.atguigu</groupId> <artifactId>pro-ssm</artifactId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>pro04-spring-ioc-xml</artifactId> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> </dependency> </dependencies> </project>
3、Person.java
javapackage com.atguigu.ioc; public class Person { public void sayHello() { System.out.println("Hello Spring!"); } }
4、applicationContext.xml
XML<?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"> <bean id="p01" class="com.atguigu.ioc.Person"></bean> </beans>
5、PersonTest.java
javapackage com.atguigu.ioc; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; public class PersonTest { @Test public void test01() { new Person().sayHello(); } @Test public void test02() { BeanFactory beanFactory = new ClassPathXmlApplicationContext("applicationContext.xml"); Person p01 = (Person) beanFactory.getBean("p01"); p01.sayHello(); } }
Maven工程继承关系,多个模块要使用同一个框架,它们应该是同一个版本,项目中使用的框架版本需要统一管理。
丁总学Java2023-11-21 22:57
相关推荐
世间万物皆对象10 分钟前
Spring Boot核心概念:日志管理没书读了39 分钟前
ssm框架-spring-spring声明式事务小二·1 小时前
java基础面试题笔记(基础篇)开心工作室_kaic1 小时前
ssm161基于web的资源共享平台的共享与开发+jsp(论文+源码)_kaic懒洋洋大魔王1 小时前
RocketMQ的使⽤武子康1 小时前
Java-06 深入浅出 MyBatis - 一对一模型 SqlMapConfig 与 Mapper 详细讲解测试转世成为计算机大神2 小时前
易考八股文之Java中的设计模式?qq_327342732 小时前
Java实现离线身份证号码OCR识别阿龟在奔跑3 小时前
引用类型的局部变量线程安全问题分析——以多线程对方法局部变量List类型对象实例的add、remove操作为例飞滕人生TYF3 小时前
m个数 生成n个数的所有组合 详解