org.springframework.web.SpringServletContainerInitializer kann nicht umgewandelt werden, javax.- servlet.ServletContainerInitializer — Eclipse-Spring-Projekt

bitte lassen Sie mich damit beginnen, Ihnen zu sagen, was ich zu tun beabsichtigen. Ich beabsichtige, Folgen Sie durch das tutorial "Aufbau eines RESTful Web-Service' genau wie bereits in der Springframework website
http://spring.io/guides/gs/rest-service/

Mein problem ist die Einstellung der Umgebung, so kann ich starten Sie einen ersten Prototyp. Ich bin angewiesen auf die Eclipse IDE auf einem Windows 7 64-bit-Maschine. Das Projekt basiert auf einem 'gradle' build-Datei. Ich bekomme die Fehlermeldung, wenn ich versuche zu laufen, das Projekt mit aufzubauen.gradle. Hier ist, wie ich versucht bin, um das Projekt auszuführen.

In das Fenster Projekt-explorer mit der rechten Maustaste auf das Projekt>Ausführen Als>Gradle build>tomcatrun

Den build.gradle-Datei ist wie folgt:

apply plugin: 'war'
apply plugin: 'tomcat'
apply plugin: 'java'
apply plugin: 'propdeps'
apply plugin: 'propdeps-maven'
apply plugin: 'propdeps-idea'
apply plugin: 'propdeps-eclipse'
apply plugin: 'eclipse'
apply plugin: 'idea'

buildscript {
  repositories {
    mavenCentral()
    maven {
      url "http://download.java.net/maven/2"
    }
    maven { url 'http://repo.spring.io/plugins-release' }
  }

  dependencies {
    classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:0.9.8'
    classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.1'
  }
}


repositories {
    mavenCentral()
}

dependencies {
    def tomcatVersion = '7.0.12'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
    tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
      exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
    }

    compile 'org.springframework:spring-core:3.2.3.RELEASE'
    compile 'org.springframework:spring-webmvc:3.2.3.RELEASE'
    compile 'com.jayway.jsonpath:json-path:0.8.1'

    compile 'org.slf4j:slf4j-api:1.7.5'
    runtime 'org.slf4j:slf4j-jdk14:1.7.5'
    runtime 'com.fasterxml.jackson.core:jackson-core:2.2.2'
    runtime 'com.fasterxml.jackson.core:jackson-databind:2.2.2'
    runtime 'javax.xml.bind:jaxb-api:2.2.9'

    provided 'javax.servlet:javax.servlet-api:3.0.1' 

    testCompile 'com.jayway.jsonpath:json-path-assert:0.8.1'
    testCompile 'org.springframework:spring-test:3.2.3.RELEASE'
    testCompile 'junit:junit:4.+'
    testCompile "org.mockito:mockito-all:1.9.5"

}

task wrapper(type: Wrapper) {
    gradleVersion = '1.6'
}

tomcatRunWar.contextPath = ''

Ich denke, dass das problem richtig definieren-Abhängigkeit mit dem Paket.
'javax.servlet:javax.servlet-api:3.0.1'

Einige andere Verweise auf die web-erwähnen, die Versorgung der "sofern" - Attribut in den build-Datei. Das Stichwort ist in der Tat in der Datei vorhanden. Ich habe versucht, auf der Suche, wie man das gleiche tun auf einige gradle Dokumentation (falls etwas fehlt), aber ich kann nicht, das problem zu lokalisieren. Das tutorial geht davon aus, dass Sie die build-in einer linux-shell. Ich glaube, es gibt eine Sache, über die Verwendung der eclipse-IDE, die den Fehler auslöst. Jede Hilfe wird geschätzt. Hier ist die WebApplicationInitializer Datei:

//{!begin top}
package com.yummynoodlebar.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;
import java.util.Set;

public class WebAppInitializer implements WebApplicationInitializer {

  private static Logger LOG = LoggerFactory.getLogger(WebAppInitializer.class);
//{!end top}

  //{!begin onStartup}
  @Override
  public void onStartup(ServletContext servletContext) {
    WebApplicationContext rootContext = createRootContext(servletContext);

    configureSpringMvc(servletContext, rootContext);
  }
  //{!end onStartup}

  //{!begin createRootContext}
  private WebApplicationContext createRootContext(ServletContext servletContext) {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(CoreConfig.class);
    rootContext.refresh();

    servletContext.addListener(new ContextLoaderListener(rootContext));
    servletContext.setInitParameter("defaultHtmlEscape", "true");

    return rootContext;
  }
  //{!end createRootContext}

  //{!begin configureTop}
  private void configureSpringMvc(ServletContext servletContext, WebApplicationContext rootContext) {
    AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
    mvcContext.register(MVCConfig.class);

    mvcContext.setParent(rootContext);

    //{!end configureTop}
    //{!begin configureBottom}
    ServletRegistration.Dynamic appServlet = servletContext.addServlet(
        "webservice", new DispatcherServlet(mvcContext));
    appServlet.setLoadOnStartup(1);
    Set<String> mappingConflicts = appServlet.addMapping("/");

    if (!mappingConflicts.isEmpty()) {
      for (String s : mappingConflicts) {
        LOG.error("Mapping conflict: " + s);
      }
      throw new IllegalStateException(
          "'webservice' cannot be mapped to '/'");
    }
    //{!end configureBottom}
  }
}

Vielen Dank!

InformationsquelleAutor apil.tamang | 2014-02-11
Schreibe einen Kommentar