spring - Java SpringMVC autowired BeanCreationException -


i using spring mvc on tomcat. when try start tomcat exception:

warning: exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.beancreationexception: error creating bean name 'requestmappinghandlermapping' defined in class org.springframework.web.servlet.config.annotation.delegatingwebmvcconfiguration: invocation of init method failed; nested exception java.lang.nosuchmethoderror: org.springframework.web.bind.annotation.requestmapping.path()[ljava/lang/string;     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1578)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:545)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:482)     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:305)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:301)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:196)     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:772)     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:834)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:537)     @ org.springframework.web.servlet.frameworkservlet.configureandrefreshwebapplicationcontext(frameworkservlet.java:667)     @ org.springframework.web.servlet.frameworkservlet.initwebapplicationcontext(frameworkservlet.java:539)     @ org.springframework.web.servlet.frameworkservlet.initservletbean(frameworkservlet.java:493)     @ org.springframework.web.servlet.httpservletbean.init(httpservletbean.java:136)     @ javax.servlet.genericservlet.init(genericservlet.java:158)     @ org.apache.catalina.core.standardwrapper.initservlet(standardwrapper.java:1231)     @ org.apache.catalina.core.standardwrapper.load(standardwrapper.java:1034)     @ org.apache.catalina.core.standardcontext.loadonstartup(standardcontext.java:4913)     @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5200)     @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150)     @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1409)     @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1399)     @ java.util.concurrent.futuretask.run(futuretask.java:266)     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617)     @ java.lang.thread.run(thread.java:745) caused by: java.lang.nosuchmethoderror: org.springframework.web.bind.annotation.requestmapping.path()[ljava/lang/string;     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandlermapping.createrequestmappinginfo(requestmappinghandlermapping.java:257)     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandlermapping.createrequestmappinginfo(requestmappinghandlermapping.java:214)     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandlermapping.getmappingformethod(requestmappinghandlermapping.java:193)     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandlermapping.getmappingformethod(requestmappinghandlermapping.java:53)     @ org.springframework.web.servlet.handler.abstracthandlermethodmapping$1.matches(abstracthandlermethodmapping.java:210)     @ org.springframework.web.method.handlermethodselector$1.dowith(handlermethodselector.java:62)     @ org.springframework.util.reflectionutils.dowithmethods(reflectionutils.java:524)     @ org.springframework.web.method.handlermethodselector.selectmethods(handlermethodselector.java:57)     @ org.springframework.web.servlet.handler.abstracthandlermethodmapping.detecthandlermethods(abstracthandlermethodmapping.java:207)     @ org.springframework.web.servlet.handler.abstracthandlermethodmapping.inithandlermethods(abstracthandlermethodmapping.java:182)     @ org.springframework.web.servlet.handler.abstracthandlermethodmapping.afterpropertiesset(abstracthandlermethodmapping.java:163)     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandlermapping.afterpropertiesset(requestmappinghandlermapping.java:133)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1637)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1574)     ... 25 more 

src:

controller:

@controller public class indexcontroller {      private final logger logger = loggerfactory.getlogger(indexcontroller.class);     private final taskstorage storage;      @autowired     public indexcontroller(taskstorage storage) {         this.storage = storage;      }      @requestmapping(value = "/", method = requestmethod.get)     public string index(map<string, object> model) {         model.put("tasks", storage.getalltasks());          return "index";     } ... 

service:

@service public class taskstorage {      public taskstorage() {      }      public void gitcreatebranch(string key, string branchname) {         servicemanager.get().git.createbranch(branchname);     } ... 

service manager:

public class servicemanager {      private static volatile servicemanager instance;      public final jiraservice jira;     public final gitservice git;     public final jenkinsservice jenkins;      @autowired     private serviceconfiguration conf;      private servicemanager() {         this.jira = new jiraservicesynchronousimpl(conf);         this.git = new jgitgitserviceimpl(conf);         this.jenkins = new simplejenkinsserviceimpl(conf);     }      public static servicemanager get() {         if (instance == null) {             synchronized (servicemanager.class) {                 if (instance == null) {                     instance = new servicemanager();                 }             }         }         return instance;     } 

service configuration:

package com.etnetera.dev.storage;  @component public class serviceconfiguration {      public final jiraconfiguration jira;     public final gitconfiguration git;     public final jenkinsconfiguration jenkins;     public final jnpconfiguration jnp;      public serviceconfiguration() {         this(null, null, null, null);     }      @autowired     public serviceconfiguration(jiraconfiguration jira, gitconfiguration git,             jenkinsconfiguration jenkins, jnpconfiguration jnp) {         super();         this.jira = jira;         this.git = git;         this.jenkins = jenkins;         this.jnp = jnp;     }      @bean     public static propertysourcesplaceholderconfigurer propertyconfigin() {         return new propertysourcesplaceholderconfigurer();     }      @component     public static class jenkinsconfiguration {         public final string url;         public final string defaultjobname;         public final string defaultjobnameparam;         public final string username;         public final string password;          public jenkinsconfiguration() {             this(null, null, null, null, null);         }          @autowired         public jenkinsconfiguration(                 @value("${jenkins.url}") string url,                 @value("${jenkins.defaultjobname}") string defaultjobname,                 @value("${jenkins.defaultjobnameparam}") string defaultjobnameparam,                 @value("${jenkins.username}") string username,                 @value("${jenkins.password}") string password) {             super();             this.url = url;             this.defaultjobname = defaultjobname;             this.defaultjobnameparam = defaultjobnameparam;             this.username = username;             this.password = password;         }          public string getjoburl(string jobname) {             return getjoburl(jobname, null);         }     }      @component     public static class gitconfiguration {         public final git git;         public final string localrepopath;          public gitconfiguration() throws ioexception {             this(null);         }          @autowired         public gitconfiguration(                 @value("${git.localrepopath}") string localrepopath)                 throws ioexception {             this.git = new git(new filerepository(localrepopath + "/.git"));             this.localrepopath = localrepopath;         }     }      @component     public static class jiraconfiguration {         public final jirarestclient client;         public final searchrestclient searchclient;         public final issuerestclient issueclient;         public final string jirauser;          public jiraconfiguration() throws urisyntaxexception {             this(null, null, null);         }          @autowired         public jiraconfiguration(@value("${jira.username}") string username,                 @value("${jira.pass}") string pass,                 @value("${jira.url}") string url) throws urisyntaxexception {             this.jirauser = username;              jirarestclientfactory factory = new asynchronousjirarestclientfactory();             uri uri = new uri(url);             this.client = factory.createwithbasichttpauthentication(uri,                     username, pass);             this.searchclient = client.getsearchclient();             this.issueclient = client.getissueclient();         }     }      @component     public static class jnpconfiguration {         public final map<string, string> serviceurls;         public final string defaultserviceurl;         public final string defaultprojectname;          public jnpconfiguration() {             this(null, null);         }          @autowired         public jnpconfiguration(                 @value("${jnp.defaultserver}") string defaultserviceurl,                 @value("${jnp.defaultprojectname}") string defaultprojectname) {             super();             this.serviceurls = null;             this.defaultserviceurl = defaultserviceurl;             this.defaultprojectname = defaultprojectname;         }     } } 

web config:

package com.etnetera.dev.config;  @enablewebmvc @configuration @componentscan({ "com.etnetera.dev.web" })  public class springwebconfig extends webmvcconfigureradapter {      @override     public void addresourcehandlers(resourcehandlerregistry registry) {         registry.addresourcehandler("/resources/**").addresourcelocations("/resources/");     }      @bean     public internalresourceviewresolver viewresolver() {         internalresourceviewresolver viewresolver = new internalresourceviewresolver();         viewresolver.setviewclass(jstlview.class);         viewresolver.setprefix("/web-inf/views/jsp/");         viewresolver.setsuffix(".jsp");         return viewresolver;     }  } 

root config:

package com.etnetera.dev.config;  @configuration @componentscan({ "com.etnetera.dev.storage" }) @propertysource("classpath:service.config.properties") public class springrootconfig {   } 

properties file located in

/src/main/resources

gradle script:

apply plugin: 'java' apply plugin: 'war' apply plugin: 'eclipse-wtp' //apply plugin: 'jetty' apply plugin: 'org.akhikhl.gretty'  buildscript {   repositories {     jcenter()   }    dependencies {     classpath 'org.akhikhl.gretty:gretty:+'   } }  gretty {   port = 8081   contextpath = 'spring4'   servletcontainer = 'jetty9' }  // jdk 7 sourcecompatibility = 1.8 targetcompatibility = 1.8  repositories {     maven { url = 'https://maven.atlassian.com/content/repositories/atlassian-public/'}     mavenlocal()     mavencentral() }  dependencies {      compile(         ['org.eclipse.jgit:org.eclipse.jgit:4.0.1.201506240215-r'],         ['com.atlassian.jira:jira-rest-java-client:2.0.0-m2'],         ['javax.servlet:jstl:1.2'],         ['org.springframework:spring-webmvc:4.2.1.release'],         ['org.springframework:spring-aspects:4.2.1.release'],         ['ch.qos.logback:logback-classic:1.1.3'])      //include in compile only, exclude in war     providedcompile 'javax.servlet:servlet-api:2.5'  }  //for eclipse ide eclipse {    wtp {     component {        //define context path, default project folder name       contextpath = 'spring4'      }    } } 

i have linked gradle dependencies in eclipse project , web app libraries seems same. both have spring in version 4.2.1.release

there no spring libs in tomcat8/lib

in eclipse tomcat has linked spring libs in version 4.2.1.release (found under tomcat 8 overview -> launch configuration -> source)

i kinda newbie spring , have tried googling solutions few hours no luck. help.

i have resolved issue cleaning project, cleaning tomcat , cleaning tomcat work dir.

anyway had issue code:

public class servicemanager {      private static volatile servicemanager instance;      public final jiraservice jira;     public final gitservice git;     public final jenkinsservice jenkins;      @autowired     private serviceconfiguration conf;      private servicemanager() {         this.jira = new jiraservicesynchronousimpl(conf);         this.git = new jgitgitserviceimpl(conf);         this.jenkins = new simplejenkinsserviceimpl(conf);     } 

it wrong because spring doesn't autowire field use in constructor. fixed this:

public class servicemanager {      private static volatile servicemanager instance;      public final jiraservice jira;     public final gitservice git;     public final jenkinsservice jenkins;      @autowired     private servicemanager(serviceconfiguration conf) {         this.jira = new jiraservicesynchronousimpl(conf);         this.git = new jgitgitserviceimpl(conf);         this.jenkins = new simplejenkinsserviceimpl(conf);     } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -