0
votes

Hi i am new to spring MVC. I am developeing a simple form in spring MVC in which i am getting the following error.Since 2 days i am trying hard to sole this but could not solve this. Please help me to resolve this so that i can make further progress.I think that its due to any jar file but unable to reach the right answer. Following jars i am using:

aopalliance-1.0.jar

commons-dbcp-1.1-rc2.jar

commons-logging-1.2.jar

commons-pool-1.1.jar

javax.servlet-api-3.1.0.jar

jstl-1.2.jar

spring-aop-4.2.0.RELEASE.jar

spring-beans-3.0.5.RELEASE.jar

spring-context-3.1.1.RELEASE.jar

spring-core-4.2.2.RELEASE.jar

spring-expression-4.2.2.RELEASE.jar

spring-web-4.2.2.RELEASE.jar

spring-webmvc-3.0.0.RELEASE.jar

i can post complete code if required. Please let me know.


<Oct 12, 2017 11:40:32 PM IST> <Error> <HTTP> <BEA-101216> <Servlet: "SM_FormHandling" failed to preload on startup in Web application: "SM_FormHandling".
java.lang.NoSuchMethodError: org.springframework.core.io.ResourceEditor.<init>(Lorg/springframework/core/io/ResourceLoader;)V
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:117)
    at javax.servlet.GenericServlet.init(GenericServlet.java:240)
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:337)
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:288)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    Truncated. see log file for complete stacktrace
> 
<Oct 12, 2017 11:40:32 PM IST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "169334801172819" for task "29". Error is: "weblogic.application.ModuleException: java.lang.NoSuchMethodError: org.springframework.core.io.ResourceEditor.<init>(Lorg/springframework/core/io/ResourceLoader;)V"
weblogic.application.ModuleException: java.lang.NoSuchMethodError: org.springframework.core.io.ResourceEditor.<init>(Lorg/springframework/core/io/ResourceLoader;)V
    at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
    at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:216)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:211)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
    Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodError: org.springframework.core.io.ResourceEditor.<init>(Lorg/springframework/core/io/ResourceLoader;)V
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:117)
    at javax.servlet.GenericServlet.init(GenericServlet.java:240)
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:337)
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:288)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    Truncated. see log file for complete stacktrace

StudentController.java

@Controller
class StudentController {

    @RequestMapping(value="/student" ,method=RequestMethod.GET)
    public ModelAndView student(){
        return new ModelAndView("student","command",new Student());
    }

    @RequestMapping(value="/addStudent" ,method=RequestMethod.POST)
    public String addStudent(@ModelAttribute("SpringWeb")Student student,ModelMap model){
        model.addAttribute("name",student.getName());
        model.addAttribute("age",student.getAge());
        model.addAttribute("id",student.getId());
        return "result";    
    }
}
1
Use same version(Spring) of jars to ignore compatibility issue in web application development, or use Maven.and show some extra codes from Controller class. - BHAR4T
added studentcontroller.java. When just inclding jar files is simple than what is need of maven dependancy in POM.xml?? - nirmal sharma
It seems to be version compatibility error, use latest versions of all jars if you don't want to use maven. Atleast download latest version of jars from maven website mvnrepository.com - Amit K Bist
Stop mixing Spring version you are mixing jars from Spring 3.0.0, 3.0.5, 3.1.1, 4.2.0 and 4.2.2. Ofcourse it won't work. Which already shows the need for something like maven or gradle, you don't need to hunt for proper jars and there related versions. With it you would only need to declare a dependency on spring-webmvc and all other related/needed jars will be added automatically. - M. Deinum

1 Answers

0
votes

The problem is that you are mixing jars from 5 different versions of Spring. You are using jars from 3.0.0, 3.0.5, 3.1.1, 4.2.0 and 4.2.2 which will, obviously, break. Never mix different versions of jars belonging to a framework.

In this day and age it is recommended to use a dependency management tool / build tool like Maven or Gradle. That way you don't need to search for the needed dependencies for a certain jar.

So instead of searching the internet (or your local computer) for jars that might work together use Maven or Gradle to do that for you.

Using maven you would write a pom.xml and which would contain something like the following.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>groupId</groupId>
  <artifactId>artifactid</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>Your-Project</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.version>4.2.2.RELEASE</spring.version>
  </properties>

  <dependencies>
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-aop</artifactId>
          <version>${spring.version}</version>
      <dependency>
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>${spring.version}</version>
      <dependency>
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>3.1.0</version>
          <scope>provided</scope>
      </dependency>
      <dependency>
          <groupId>jstl</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
      </dependency>
      <dependency>
          <groupId>commons-dbcp</groupId>
          <artifactId>commons-dbcp</artifactId>
          <version>1.4</version>
      <dependency>
  </dependencies>  
</project>

Which contains everything needed to obtain all proper dependencies. You don't need to know which dependencies there are for spring-webmvc as those will be added automatically. You were also using a old snapshot/milestone for commons-dbcp you probably want to use a release version (although I would suggest using HikariCP as a connection pool instead of Commons DBCP).

The same in a build.gradle.

apply plugin: 'war'

ext['springVersion'] = '4.2.2.RELEASE'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.springframework:spring-aop:$springVersion"
    compile "org.springframework:spring-webmvc:$springVersion"
    compile 'commons-dbcp:commons-dbcp:1.4'
    compile 'jstl:jstl:1.2'
    providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
}

Next to managing dependencies these tools can help you with a lot of other things as well. Check the documentation and the different plugins for the tools on how these will/can help you. It will at least save you a lot of headaches searching for the right combination of dependencies.