这应该工作,我刚刚创建了2个项目并进行了检查。
项目A(使用STS创建的标准Maven项目)
applicationContext.xml位于
src / main / resources中。
pom.xml:
<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>org.D</groupId><artifactId>A</artifactId><version>0.0.1-SNAPSHOT</version><properties> <spring.version>3.0.5.RELEASE</spring.version></properties><dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency></dependencies></project>applicationContext.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="myAdder" > <property name="foo" value="bar" /></bean></beans>
项目B:
pom.xml:与A相同,只是添加了A作为依赖项:<dependency> <groupId>org.D</groupId> <artifactId>A</artifactId> <version>0.0.1-SNAPSHOT</version></dependency>
项目B中的Start.java:
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( "classpath*:**/applicationContext*.xml"); MyAdder myAdder = (MyAdder) context.getBean("myAdder"); System.out.println(myAdder.getFoo());}mvn首先安装A,然后在项目B中运行“启动”。



