相关疑难解决方法(0)

如何将一个项目的spring-config.xml导入另一个项目的spring-config.xml?

我有两个名字simple-core-impl和项目simple-core-web.

两个项目都是,spring based并且都有一个父项目名称simple-core.

simple-impl-config.xmlsimple-core-impl项目和simple-web-config.xmlsimple-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.

java spring

74
推荐指数
4
解决办法
17万
查看次数

spring - @ContextConfiguration无法在src/test/resources中加载配置文件

我尝试使用以下抽象类在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无法加载它.

谢谢.

java junit spring maven-2 junit4

25
推荐指数
3
解决办法
7万
查看次数

RunWith和ContextConfiguration很奇怪的行为

我有这个非常简单的课程:

 @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 junit spring unit-testing

8
推荐指数
1
解决办法
4785
查看次数

Java - jar文件的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)

任何想法如何快速解决这个问题?

spring properties placeholder

6
推荐指数
1
解决办法
3560
查看次数

标签 统计

spring ×4

java ×3

junit ×2

junit4 ×1

maven-2 ×1

placeholder ×1

properties ×1

unit-testing ×1