我有两个名字simple-core-impl和项目simple-core-web.
两个项目都是,spring based并且都有一个父项目名称simple-core.
我simple-impl-config.xml在simple-core-impl项目和simple-web-config.xml中simple-impl-config.xml.
我有一个bean有一个类:simple service有一个方法给我一个消息"hello World".
我想导入simple-impl-config.xml,simple-web-config.xml所以bean可以进入simple-core-web项目中的控制器.
simple-core-web项目有一个simple-core-impl项目.
那么请告诉我如何将spring-config.xml一个项目导入到spring-config.xml另一个项目中,这样所有的第一个bean都可以通过导入进入其他项目?
我不想重写所有的bean.
我尝试使用以下抽象类在src/test/resources类路径中加载spring配置文件:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:/applicationContext.xml"})
public class BaseIntegrationTests {
}
Run Code Online (Sandbox Code Playgroud)
我在src/test/resources中有applicationContext.xml文件,但Spring无法加载它.
谢谢.
我有这个非常简单的课程:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:/application-context-this-does-not-exist.xml"})
public class HTMLSourceExtractorImplTest {
@Autowired
ApplicationContext context;
@Test
public void test(){
String [] beans = context.getBeanDefinitionNames();
for(String bean : beans){
System.out.println(bean);
}
System.out.println("Testing");
}
}
Run Code Online (Sandbox Code Playgroud)
在类路径中指定的此上下文文件不存在.我几乎可以放任何我想要的名字,但代码不会破坏.我的意思是测试运行得很好,好像该文件确实存在.
如果我做一个小的改动,从:classpath*到classpath,那么它就是beaks,说这个文件不存在,这也是我在第一种情况下所期望的行为.
Spring Version 3.2.3.RELEASE.
有人可以解释这种奇怪的行为吗?
编辑
建议的日志:
20:47:26,923 INFO [GenericApplicationContext] Refreshing org.springframework.context.support.GenericApplicationContext@3df6c65c: startup date [Fri Jun 07 20:47:26 PDT 2013]; root of context hierarchy
Run Code Online (Sandbox Code Playgroud)
我甚至尝试从应用程序上下文输出所有bean:
org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.annotation.ConfigurationClassProcessor.importAwareProcessor
Run Code Online (Sandbox Code Playgroud)
在我看来,如果是通配符,Spring将创建一个默认的空应用程序上下文
Java-Spring我有基于模块的项目,我有DAO层模块和业务层模块,它依赖于DAO层和依赖于DAO层和业务层的web层.
我正在使用maven进行项目编译.和jar的每个组件都是web项目lib文件夹下的组.
问题是我在DAO jar中有弹簧上下文文件和.property文件,以下是我的配置,但我春天无法加载属性我也试过前缀value="classpath:abc.properties但它没有用.
当我打开DAO jar时,spring上下文和.properties文件都在root上.
<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="abc.properties" />
</bean>
<bean id="cmfModelDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="${jdbc.ConnectionUrl}"/>
<property name="username" value="${jdbc.Username}"/>
<property name="password" value="${jdbc.Password}"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
任何想法如何快速解决这个问题?