Spring 3.0.5 기반에서 Test 에러

569 views
Skip to first unread message

BumChul-Joung

unread,
May 4, 2011, 3:45:00 AM5/4/11
to ks...@googlegroups.com
안녕하십니까?
매일 보기만 하다가 궁금한 것이 있어서 올립니다.
Maven환경을 구축하고 스프링 프레임웍에 테스트 환경을 구축하는데 아래의 에러가 나네요..
문제가 뭘까요? 아시는 분들 조언을 부탁드립니다.

에러 메세지
 
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'core_mysqlDataSource' must be of type [org.springframework.transaction.PlatformTransactionManager], but was actually of type [org.apache.commons.dbcp.BasicDataSource]
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:349)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
 at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1079)
 at org.springframework.test.context.transaction.TransactionalTestExecutionListener.getTransactionManager(TransactionalTestExecutionListener.java:308)
 at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:158)
 at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:358)
 at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
 at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
 at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
 at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
 at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
 
Maven POM.xml
 
  <groupId>kr.co.comas</groupId>
  <artifactId>oobf.core</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>oobf.core</name>
  <url>http://maven.apache.org</url>
  <profiles>
   <profile>
    <id>local</id>
    <activation>
     <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
     <environment>local</environment>
    </properties>
   </profile>
   <profile>
    <id>development</id>
    <properties>
     <environment>development</environment>
    </properties>
   </profile>
   <profile>
    <id>production</id>
    <properties>
     <environment>production</environment>
     <test.skip>true</test.skip>
    </properties>
   </profile>
  </profiles> 
  <dependencyManagement>
   <dependencies>
   </dependencies>
  </dependencyManagement>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.maven.version>3.0.5.RELEASE</spring.maven.version>
  </properties>
  <licenses>
 <license>
  <name>Apache License, Version 2.0</name>
  <url>http://www.apache.org/licenses/LICENSE-2.0
  </url>
  <comments>
   Copyright 2006-2007 the original author or authors.
   Licensed under the Apache License, Version 2.0 (the
   "License"); you
   may not use this file except in
   compliance with the License. You may
   obtain a copy of
   the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by
   applicable law or agreed to in
   writing, software distributed under
   the License is
   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied. See
   the License
   for the specific language governing
   permissions and limitations under
   the License.
  </comments>
 </license>
  </licenses>   
  <pluginRepositories>
    <pluginRepository>
   <id>maven-repo</id>
   <name>maven repo</name>
   <url>http://repo1.maven.org/maven2/
   </url>
 </pluginRepository>
  </pluginRepositories>
  <repositories>
 <repository>
  <id>com.springsource.repository.bundles.release
  </id>
  <name>SpringSource Enterprise Bundle Repository -
   SpringSource Bundle Releases</name>
  <url>http://repository.springsource.com/maven/bundles/release
  </url>
 </repository>
 <repository>
  <id>com.springsource.repository.bundles.external
  </id>
  <name>SpringSource Enterprise Bundle Repository -
   External Bundle Releases</name>
  <url>http://repository.springsource.com/maven/bundles/external
  </url>
 </repository>
    <repository>      
     <id>repository.jboss.org</id>      
     <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>      
     <snapshots>        
      <enabled>false</enabled>      
     </snapshots>    
    </repository> 
 <repository>
  <id>com.springsource.repository.libraries.release
  </id>
  <name>SpringSource Enterprise Bundle Repository -
   SpringSource Library Releases</name>
  <url>http://repository.springsource.com/maven/libraries/release
  </url>
 </repository>
 <repository>
  <id>com.springsource.repository.libraries.external
  </id>
  <name>SpringSource Enterprise Bundle Repository -
   External Library Releases</name>
  <url>http://repository.springsource.com/maven/libraries/external
  </url>
 </repository>
 <repository>
  <id>spring-release</id>
  <name>Spring Portfolio Release Repository</name>
  <url>http://maven.springframework.org/release
  </url>
 </repository>
 <repository>
  <id>spring-external</id>
  <name>Spring Portfolio Release Repository</name>
  <url>http://maven.springframework.org/external
  </url>
 </repository>
 <repository>
  <id>spring-milestone</id>
  <name>Spring Portfolio Milestone Repository</name>
  <url>http://maven.springframework.org/milestone
  </url>
 </repository>
 <repository>
  <id>spring-ext</id>
  <name>Spring External Dependencies Repository</name>
  <url>
   http://springframework.svn.sourceforge.net/svnroot/springframework/repos/repo-ext/
  </url>
 </repository>
 <!-- used when building against Spring snapshots -->
 <repository>
  <id>spring-snapshot</id>
  <name>Spring Portfolio Milestone Repository</name>
  <url>http://maven.springframework.org/snapshot
  </url>
  <snapshots>
   <enabled>true</enabled>
  </snapshots>
 </repository>
  </repositories> 
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
     <groupId>javax.servlet</groupId>
     <artifactId>servlet-api</artifactId>
     <version>2.5</version>
     <type>jar</type>
     <scope>compile</scope>
    </dependency>
 <dependency>
     <groupId>geronimo-spec</groupId>
     <artifactId>geronimo-spec-jms</artifactId>
     <version>1.1-rc4</version>
 </dependency>
 <dependency>
   <groupId>org.apache.httpcomponents</groupId>
   <artifactId>httpclient</artifactId>
   <version>4.0-beta2</version>
 </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>
    </dependency>
 <dependency>
     <groupId>quartz</groupId>
     <artifactId>quartz</artifactId>
     <version>1.5.2</version>
 </dependency>
  <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.2</version>
    <type>jar</type>
    <scope>compile</scope>
  </dependency> 
 
  <!--Spring Framework Start //-->
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>org.springframework.core
  </artifactId>
  <version>${spring.maven.version}
  </version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>org.springframework.context
  </artifactId>
  <version>${spring.maven.version}
  </version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>org.springframework.context.support
  </artifactId>
  <version>${spring.maven.version}
  </version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>org.springframework.beans
  </artifactId>
  <version>${spring.maven.version}
  </version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>org.springframework.aop
  </artifactId>
  <version>${spring.maven.version}
  </version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>org.springframework.web.servlet
  </artifactId>
  <version>${spring.maven.version}
  </version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>org.springframework.test
  </artifactId>
  <version>${spring.maven.version}
  </version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jms</artifactId>
  <version>${spring.maven.version}</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency>  
  <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>${spring.maven.version}</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency>
 <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-tx</artifactId>
     <version>${spring.maven.version}</version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-orm</artifactId>
  <version>${spring.maven.version}</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aspects</artifactId>
  <version>${spring.maven.version}</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency> 
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-ibatis</artifactId>
  <version>2.0.8</version>
  <exclusions>
   <exclusion>
    <groupId>org.springframework</groupId>
       <artifactId>spring-dao</artifactId>   
   </exclusion>
  </exclusions>   
  <type>jar</type>
  <scope>compile</scope>
 </dependency> 
  
 <dependency>
     <groupId>commons-configuration</groupId>
     <artifactId>commons-configuration</artifactId>
     <version>1.6</version>
 </dependency>
 <dependency>
     <groupId>commons-beanutils</groupId>
     <artifactId>commons-beanutils</artifactId>
     <version>1.8.3</version>
 </dependency>
 <!-- WEB -->
 <dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>
   com.springsource.org.apache.commons.collections
  </artifactId>
  <version>3.2.0</version>
 </dependency> 
 <dependency>
  <groupId>org.apache.ant</groupId>
  <artifactId>ant</artifactId>
  <version>1.8.2</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency>
 <dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.14</version>
  <type>jar</type>
 </dependency>
 <dependency>
  <groupId>javax.jms</groupId>
  <artifactId>jms</artifactId>
  <version>1.1</version>
  <scope>compile</scope>
 </dependency>
 <dependency>
     <groupId>com.caucho</groupId>
     <artifactId>hessian</artifactId>
     <version>4.0.7</version>
 </dependency>
 <dependency>
     <groupId>activecluster</groupId>
     <artifactId>activecluster</artifactId>
     <version>1.1-20050524.034300</version>
 </dependency>
 <dependency>
     <groupId>org.apache.activemq</groupId>
     <artifactId>activemq-core</artifactId>
     <version>5.5.0</version>
 </dependency>
 <dependency>
  <groupId>cglib</groupId>
  <artifactId>cglib-nodep</artifactId>
  <version>2.1_3</version>
 </dependency>
 <dependency>
  <groupId>commons-dbcp</groupId>
  <artifactId>commons-dbcp</artifactId>
   <version>1.4</version>
  </dependency>
 
 <dependency>
  <groupId>javax.transaction</groupId>
  <artifactId>jta</artifactId>
  <version>1.1</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency>
  <dependency>
  <groupId>org.jboss.netty</groupId>
  <artifactId>netty</artifactId>
  <version>3.2.0.BETA1</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency> 
 <dependency>
   <groupId>com.jcraft</groupId>
   <artifactId>jsch</artifactId>
   <version>0.1.24</version>
 </dependency>
 <dependency>
   <groupId>com.thoughtworks.xstream</groupId>
   <artifactId>xstream</artifactId>
   <version>1.3.1</version>
 </dependency>
 <dependency>
   <groupId>com.thoughtworks.xstream</groupId>
   <artifactId>xstream-benchmark</artifactId>
   <version>1.3.1</version>
 </dependency>
 <dependency>
   <groupId>jdom</groupId>
   <artifactId>jdom</artifactId>
   <version>1.0</version>
 </dependency>
 <dependency>
  <groupId>commons-dbcp</groupId>
  <artifactId>commons-dbcp</artifactId>
  <version>1.4</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency>
 <dependency>
  <groupId>commons-logging</groupId>
  <artifactId>commons-logging-api</artifactId>
  <version>1.1</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency>
 <dependency>
     <groupId>org.mybatis</groupId>
     <artifactId>mybatis</artifactId>
     <version>2.3.5</version>  
 </dependency>
 <dependency>
     <groupId>org.antlr</groupId>
     <artifactId>stringtemplate</artifactId>
     <version>3.2.1</version>
 </dependency>
 <dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.16</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency>
 <dependency>
     <groupId>org.aspectj</groupId>
     <artifactId>aspectjtools</artifactId>
     <version>1.6.2</version>
 </dependency>
 <dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-jdk14</artifactId>
  <version>1.5.3</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-oxm</artifactId>
  <version>3.0.5.RELEASE</version>
  <type>jar</type>
  <scope>compile</scope>
 </dependency>
  </dependencies> 
  <build>
   <finalName>oobf.core</finalName>
   <resources>
    <resource>
     <directory>src/main/resources</directory>
    </resource>
    <resource>
     <directory>src/main/java</directory>
     <excludes>
      <exclude>**/*.java</exclude>
     </excludes>
    </resource>
    <resource>
     <directory>src/main/resources-${environment}</directory>
    </resource>
   </resources>
   <plugins>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.8.1</version>
   <configuration>
    <skip>${test.skip}</skip>
   </configuration>
     
    </plugin>
   </plugins>
  </build> 
</project>
 
 
<bean id="core_mysqlDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  ........ 
 </bean>

Sungchul Park

unread,
May 4, 2011, 12:37:07 PM5/4/11
to ks...@googlegroups.com
> org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean
> named 'core_mysqlDataSource' must be of type
> [org.springframework.transaction.PlatformTransactionManager], but was
> actually of type [org.apache.commons.dbcp.BasicDataSource]
왠지 모르지만 트랜잭션 관리자로 core_mysqlDataSource 빈을 취했더니 해당
빈이 PlatformTransactionManager 타입이 아니라서 예외 상황이 발생했습니다.

이건 메이븐 문제가 아니고 스프링 설정과 테스트 코드 쪽을 봐야할 문제 같
네요.

소거 절차를 밟아, 이 오류와 상관 없는 설정과 코드를 하나씩 제거한 다음에
딱 이 오류가 발생하는 최소한의 코드만 남겨서 올려주시면 문제를 정확히 파
악하는 데 도움을 드리기 쉬울 듯 합니다.

BumChul-Joung

unread,
May 5, 2011, 9:59:15 PM5/5/11
to ks...@googlegroups.com
감사합니다. 답변을 해주셔서 ^^
답변을 주신 내용을 검토하여 다시 테스트를 해봤습니다.
SpringJUnit을 이용하여 테스트를 할 경우에는 위의 에러 메세지가 발생하는데 순수하게 JUnit을 이용하여 테스트 할때는 에러가 발생하지
않는 군요..
 
짧은 저의 생각으로는 Maven의 dependency관련 에러가 아닌가 하는 생각이 들었는데 그것도 아닌것 같고. 좀 난해하군요.
혹시 갑자기 문득 확 드는 아이디어가 있다면 답변 부탁드립니다.
 
에러가 발생하는 경우
 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:/spring/core/applicationContext.xml",
  "classpath:/spring/core/applicationContext-template.xml",
  "classpath:/spring/core/applicationContext-service.xml",
  "classpath:/spring/core/applicationContext-data.xml",
  "classpath:/spring/core/applicationContext-sender.xml",
  "classpath:/spring/core/applicationContext-receiver.xml"})
@TransactionConfiguration(transactionManager="core_mysqlDataSource")
@Transactional
public class SpringAppTest {
 @Autowired
 private HostService hostService;
 
 
 @org.junit.Test
 public void testSend431001()
 {
  DataMap message = new DataMap();
  message.put(DataConstants.MESSAGE_ID, "KEFCI_431001");
  message.put(DataConstants.TRAN_CD, "431001");
  message.put(DataConstants.HANDLER, "biz");
  message.put("CondEBndNo", "088201009100000000014");
  hostService.sendHost(message);
 }
}
 
 
에러가 나지 않는 경우
 
/**
 * Unit test for simple App.
 */
public class AppTest extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }
    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }
    /**
     * Rigourous Test :-)
     */
    public void testApp()
    {
        ApplicationContext context = new ClassPathXmlApplicationContext("/spring/core/applicationContext.xml"
          ,"/spring/core/applicationContext-template.xml","/spring/core/applicationContext-service.xml",
          "/spring/core/applicationContext-data.xml","/spring/core/applicationContext-sender.xml",
          "/spring/core/applicationContext-receiver.xml");
        HostService hostService = (HostService)context.getBean("hostService");
  
        DataMap message = new DataMap();
  message.put(DataConstants.MESSAGE_ID, "KEFCI_431001");
  message.put(DataConstants.TRAN_CD, "431001");
  message.put(DataConstants.HANDLER, "biz");
  message.put("CondEBndNo", "088201009100000000014");
  hostService.sendHost(message);
    }
}

2011년 5월 5일 오전 1:37, Sungchul Park <gyu...@gmail.com>님의 말:

--
Google 그룹스 'Korea Spring User Group' 그룹에 가입했으므로 본 메일이 전송되었습니다.
이 그룹에 게시하려면 ks...@googlegroups.com(으)로 이메일을 보내세요.
그룹에서 탈퇴하려면 ksug+uns...@googlegroups.com로 이메일을 보내주세요.
더 많은 옵션을 보려면 http://groups.google.com/group/ksug?hl=ko에서 그룹을 방문하세요.




--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
정범철 (Joung Bum Chul)
나를 쓰러트리지 못하는 고통은 나를 단련시킬 뿐이다.
Tel: +82 2-6232-5041
Mobile: 010-3706-5041
E-mail: net...@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sungchul Park

unread,
May 5, 2011, 10:04:40 PM5/5/11
to ks...@googlegroups.com

> @TransactionConfiguration(transactionManager="core_mysqlDataSource")
이 부분에서 transactionManager 속성에 지정한 빈이 DataSource이기 때문에
난 에러입니다.
트랜잭션 매니저를 지정해주세요. 트랜잭션 매니저의 빈 이름이
transactionManager라면 생략하셔도 됩니다.

Sanghyuk Jung

unread,
May 5, 2011, 10:11:29 PM5/5/11
to ks...@googlegroups.com
아래 부분의 선언 부분이 문제로 보입니다.
@TransactionConfiguration(transactionManager="core_mysqlDataSource")


transactionManager가 지정하는 bean은 당연히 PlatformTransactionManager를 구현한 클래스가 지정되어야하는데, DataSource가 지정되어 있네요.

bean 선언에 아래와 같이 추가하고

<bean id="testTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 <property name="dataSource" ref="core_mysqlDataSource"/>
</bean>

선언을 아래와 같이 바꾸면 됩니다.
@TransactionConfiguration(transactionManager="testTransactionManager")

Maven과는 전혀 관계가 없는 문제입니다. 

2011년 5월 6일 오전 10:59, BumChul-Joung <netr...@gmail.com>님의 말:

BumChul-Joung

unread,
May 5, 2011, 10:24:34 PM5/5/11
to ks...@googlegroups.com
아 역시 잘되는군요..
예전에는 메일만 받아보고 읽어 보지도 않고 그냥 넘어 갔었는데 이제는 저도 열심히 메일의 내용도 확인하고 제가 답을 드릴 수 있는 부분은 답을
달아 보려고 노력해야 겠군요.
 
정말 감사합니다. 잘 되는군요..
그런데 maven 프로젝트를 전환하기 전에는 잘 돌어가던 소스였는데.. 좀 의아 스럽지만 다시한번 확인해 봐야 겠습니다.
 
수고하십시고요. 즐거운 주말 보내십시오. ^^


 
2011년 5월 6일 오전 11:11, Sanghyuk Jung <ben...@gmail.com>님의 말:
Reply all
Reply to author
Forward
0 new messages