java.lang.NoClassDefFoundError: org/springframework/messaging/converter/MessageConverter

百般思念 提交于 2019-12-11 06:46:42

问题


I am new to Spring Integration . I am not using maven and my integration-spring.xml is located inside src/resources/integration-spring.xml and all my jars are having v4.0.5+. I am getting below exception when running my JUnit Test case.

java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:331)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [resources/integration-spring.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/messaging/converter/MessageConverter
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:414)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)

integration-spring.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">

<int:gateway service-interface="com.fil.MyService" id="myGateway"
    default-request-channel="in" />

<int:service-activator input-channel="in" method="someMethod"
    ref="exampleHandler" />

<bean id="exampleHandler" class="com.fil.MyServiceImpl" />

Test.java

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import com.fil.MyService;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/resources/integration-spring.xml" })
public class MyServiceTest {

@Autowired
private MyService service; 

@Test
public void test() {
    try{
        service.single("hELLO ");
    }
    catch(Exception e){
        e.printStackTrace();
    }
}

}

回答1:


You really should use maven or gradle to manage your project's dependencies; doing it manually is just too painful - especially with regard to getting all the versions right.

NoClassDefFoundError: org/springframework/messaging/converter/MessageConverter

The org.springframework.messaging package is provided by the spring-messaging jar file from the core Spring Framework. It contains general messaging abstractions used by Spring Integration (and other Spring projects).

Since you are "new" to the framework(s), you really should be using the latest versions:

org.springframework.integration:spring-integration-core:4.3.9.RELEASE

which depends on

org.springframework:spring-messaging:4.3.8.RELEASE

by default.

v4.0.5+

You must make sure that all jars from the same project (Spring Integration or Spring Framework) have their same respective versions (spring-beans, spring-messaging, etc must match and spring-integration-* must all be the same version).



来源:https://stackoverflow.com/questions/43828663/java-lang-noclassdeffounderror-org-springframework-messaging-converter-messagec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!