java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation
java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation
当我 运行 服务器时,我在控制台上收到以下错误:
Error creating bean with name
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMa
pping#0': Invocation of init method failed; nested exception is
java.lang.NoSuchMethodError:
org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation
(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
网页出现404错误。我检查了 url 并且资源存在。
这是我的 xml 的:
spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.abhishek"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<bean id="" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:XE"></property>
<property name="username" value="system"></property>
<property name="password" value="pass"></property>
</bean>
<bean id="myJDBC" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="myDataSource"></property>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>EmployeeDetails</display-name>
<servlet>
<servlet-name>employeermvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>employeermvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param>
</web-app>
我的控制器class
package com.abhishek.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.abhishek.Dao.EmployeeDao;
import com.abhishek.bean.Employee;
@Controller
public class MyController {
@Autowired
private EmployeeDao dao;
@RequestMapping("/")
public String newEmployee(ModelMap model) {
Employee employee = new Employee();
model.addAttribute("employee", employee);
return "create";
}
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String insertEmployee(@ModelAttribute("employee") Employee employee) {
dao.insert(employee);
return "inserted";
}
}
DAoImpl :
package com.abhishek.Dao;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import com.abhishek.bean.Employee;
@Component
public class EmployeeDaoImpl implements EmployeeDao {
@Autowired
private JdbcTemplate jdbcTemplate;
public EmployeeDaoImpl(){
}
public EmployeeDaoImpl(JdbcTemplate jdbcTemplate) {
super();
this.jdbcTemplate = jdbcTemplate;
}
@Override
public void insert(Employee emp) {
String sql="insert into employee(e_id,name,desig,deptt,basic) values(?,?,?,?,?)";
jdbcTemplate.update(sql, emp.getEid(),emp.getName(),emp.getDesg(),emp.getDept(),emp.getBasic());
System.out.println("Record Inserted!!!");
}
}
这可能是因为多个相同的 jar 文件具有不同的版本。确保您没有多个具有不同版本 Spring.
的 jar 文件
您的 bean 尚未配置。
在 spring-servlet.xml
中配置它
<bean id="employeeDao" class="com.abhishek.EmployeeDao">
<property name="jdbcTemplate" ref="myJDBC"></property>
</bean>
还要查看以下内容。
- 检查你的jar包是否有需要的方法
- 检查相同的方法是否不能在多个 jar 中,以便它们都试图将索引提供给 jvm,而 JVM 混淆选择正确。
- 列出你的 jars/dependency 删除不必要的
- 使用maven下载需要的依赖或者从spring.io/projects,grepcode.
下载
LAST sometime we have required jar but we do not have required method
may be due to legacy etc so please choose appropriate jar for it.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]: Factory method 'requestMappingHandlerMapping' threw exception; nested exception is java.lang.NoSuchMethodError: 'java.lang.annotation.Annotation org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class)'
我在将我们的ant项目迁移到maven项目时也遇到了同样的问题。
调试了一整天后,根据上述数据。我观察到 activemq-all 5.13.2 jar 内部包含 Spring 个罐子。
问题之前我的maven依赖。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.13.2</version>
</dependency>
在我们的ant项目中,我们使用的是activemq-all 5.9.0 jar。通过使用这个罐子,问题得到解决。由于此版本中没有 spring 罐子。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.9.0</version>
</dependency>
结论:每当遇到此类问题时,我们都需要检查依赖项正在使用的内部 jar。
当我 运行 服务器时,我在控制台上收到以下错误:
Error creating bean with name
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMa
pping#0': Invocation of init method failed; nested exception is
java.lang.NoSuchMethodError:
org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation
(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
网页出现404错误。我检查了 url 并且资源存在。
这是我的 xml 的:
spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.abhishek"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<bean id="" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:XE"></property>
<property name="username" value="system"></property>
<property name="password" value="pass"></property>
</bean>
<bean id="myJDBC" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="myDataSource"></property>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>EmployeeDetails</display-name>
<servlet>
<servlet-name>employeermvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>employeermvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param>
</web-app>
我的控制器class
package com.abhishek.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.abhishek.Dao.EmployeeDao;
import com.abhishek.bean.Employee;
@Controller
public class MyController {
@Autowired
private EmployeeDao dao;
@RequestMapping("/")
public String newEmployee(ModelMap model) {
Employee employee = new Employee();
model.addAttribute("employee", employee);
return "create";
}
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String insertEmployee(@ModelAttribute("employee") Employee employee) {
dao.insert(employee);
return "inserted";
}
}
DAoImpl :
package com.abhishek.Dao;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import com.abhishek.bean.Employee;
@Component
public class EmployeeDaoImpl implements EmployeeDao {
@Autowired
private JdbcTemplate jdbcTemplate;
public EmployeeDaoImpl(){
}
public EmployeeDaoImpl(JdbcTemplate jdbcTemplate) {
super();
this.jdbcTemplate = jdbcTemplate;
}
@Override
public void insert(Employee emp) {
String sql="insert into employee(e_id,name,desig,deptt,basic) values(?,?,?,?,?)";
jdbcTemplate.update(sql, emp.getEid(),emp.getName(),emp.getDesg(),emp.getDept(),emp.getBasic());
System.out.println("Record Inserted!!!");
}
}
这可能是因为多个相同的 jar 文件具有不同的版本。确保您没有多个具有不同版本 Spring.
的 jar 文件您的 bean 尚未配置。 在 spring-servlet.xml
中配置它<bean id="employeeDao" class="com.abhishek.EmployeeDao">
<property name="jdbcTemplate" ref="myJDBC"></property>
</bean>
还要查看以下内容。
- 检查你的jar包是否有需要的方法
- 检查相同的方法是否不能在多个 jar 中,以便它们都试图将索引提供给 jvm,而 JVM 混淆选择正确。
- 列出你的 jars/dependency 删除不必要的
- 使用maven下载需要的依赖或者从spring.io/projects,grepcode. 下载
LAST sometime we have required jar but we do not have required method may be due to legacy etc so please choose appropriate jar for it.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]: Factory method 'requestMappingHandlerMapping' threw exception; nested exception is java.lang.NoSuchMethodError: 'java.lang.annotation.Annotation org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class)'
我在将我们的ant项目迁移到maven项目时也遇到了同样的问题。
调试了一整天后,根据上述数据。我观察到 activemq-all 5.13.2 jar 内部包含 Spring 个罐子。
问题之前我的maven依赖。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.13.2</version>
</dependency>
在我们的ant项目中,我们使用的是activemq-all 5.9.0 jar。通过使用这个罐子,问题得到解决。由于此版本中没有 spring 罐子。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.9.0</version>
</dependency>
结论:每当遇到此类问题时,我们都需要检查依赖项正在使用的内部 jar。