Spring引发NoSuchMethodError异常

时间:2017-04-01 17:47:06

标签: maven spring-boot spring-data

当我尝试运行以下代码时

@Override
public List<EventDetails> process(int event_status) throws EventDetailDataException {
    String sql="select * from MicroServiceEventDetails where  event_status=?";
    List<EventDetails> EventDetailsList = template.query(sql, new BeanPropertyRowMapper<EventDetails>(EventDetails.class),new Object[] {event_status});
    return EventDetailsList;
}

它抛出以下异常,这是错误日志: -

Apr 02, 2017 6:26:04 AM org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler handleError
SEVERE: Unexpected error occurred in scheduled task.
java.lang.NoSuchMethodError: org.springframework.core.convert.support.DefaultConversionService.getSharedInstance()Lorg/springframework/core/convert/ConversionService;
at org.springframework.jdbc.core.BeanPropertyRowMapper.<init>(BeanPropertyRowMapper.java:91)
at com.syntel.boot.dao.EventProcessDaoImpl.process(EventProcessDaoImpl.java:38)
at com.syntel.boot.services.EventDetailServiceImpl.process(EventDetailServiceImpl.java:73)
at com.syntel.boot.scheduler.microeventschudler.eventExcuter(microeventschudler.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

也许maven依赖是我不确定的原因,帮助?

1 个答案:

答案 0 :(得分:0)

我假设您正在使用Maven / Gradle,任何构建工具。 我正在开发一个spring MVC项目并添加了LDAP功能,但是我在pom.xml和我使用的jar版本的依赖列表顶部添加了LDAP jar依赖项,使用了较低版本的spring core,它没有ConversionService类。我通过回溯跟踪到我所做的Spring jar版本的最新更改(即添加了ldap libs)并使用Maven - Dependency层次结构选项卡来识别已更改的内容。一旦我删除了新的依赖项。干净,安装,将依赖项添加到列表的底部。问题已得到解决。

ensure your spring core jar is the highest version of versions refered by other jars

您解析的依赖项应该具有左侧列上引用的最高Spring核心版本。应省略任何较低版本。在屏幕截图中,请注意4.3.4中省略了spring core 4.3.9。通过添加使用较低spring核心版本的依赖项来避免这种情况,而不是那些使用更高版本的版本。