2016-03-20 71 views
0

私は問題に遭遇しましたが、エラーがかなり一般的であるためこの問題の原因を特定できません。java.lang.NoClassDefFoundError:クラスorg.springframework.web.util.NestedServletExceptionを初期化できませんでした。

java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.util.NestedServletException at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:980) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1160) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1092) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134) at org.eclipse.jetty.server.Server.handle(Server.java:518) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95) at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93) at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:246) at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:156) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572) at java.lang.Thread.run(Thread.java:745)

これは私のプロジェクト構造である:

Project Structure

それは私がSpringMVCが埋め込ま桟橋を使用するだけの非常にシンプルなプロジェクトです。

これはpom.xmlファイルです:

<?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>com.biendltb</groupId> 
<artifactId>com.biendltb.world_map</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>jar</packaging> 

<name>com.biendltb.world_map</name> 

<properties> 
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <jetty.version>9.3.8.v20160314</jetty.version> 
    <spring.version>4.2.5.RELEASE</spring.version> 
    <servlet.version>2.5</servlet.version> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-web-api</artifactId> 
     <version>7.0</version> 
     <scope>provided</scope> 
    </dependency> 

    <!-- SPRING DEPENDENCY --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <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>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-beans</artifactId> 
     <version>4.2.5.RELEASE</version> 
    </dependency> 


    <!-- JETTY DEPENDENCY --> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-server</artifactId> 
     <version>${jetty.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-servlet</artifactId> 
     <version>${jetty.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-webapp</artifactId> 
     <version>${jetty.version}</version> 
    </dependency> 

    <!-- SERVLET DEPENDENCY --> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>${servlet.version}</version> 
    </dependency> 

    <!-- COMMON LOGGING DEPENDENCY --> 
    <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     <version>1.1.3</version> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.1</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
       <compilerArguments> 
        <endorseddirs>${endorsed.dir}</endorseddirs> 
       </compilerArguments> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.6</version> 
      <executions> 
       <execution> 
        <phase>validate</phase> 
        <goals> 
         <goal>copy</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>${endorsed.dir}</outputDirectory> 
         <silent>true</silent> 
         <artifactItems> 
          <artifactItem> 
           <groupId>javax</groupId> 
           <artifactId>javaee-endorsed-api</artifactId> 
           <version>7.0</version> 
           <type>jar</type> 
          </artifactItem> 
         </artifactItems> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>jetty-maven-plugin</artifactId> 
      <version>9.3.7.v20160115</version> 
     </plugin> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.4</version> 
      <configuration> 
       <warSourceDirectory>WebContent</warSourceDirectory> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>2.4.3</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
        <configuration> 
         <createDependencyReducedPom>false</createDependencyReducedPom> 
         <transformers> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
           <mainClass>com.biendltb.main_server.TripMapServer</mainClass> 
          </transformer> 
         </transformers> 
         <filters> 
          <filter> 
           <artifact>*:*</artifact> 
           <excludes> 
            <exclude>META-INF/*.SF</exclude> 
            <exclude>META-INF/*.DSA</exclude> 
            <exclude>META-INF/*.RSA</exclude> 
           </excludes> 
          </filter> 
         </filters> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-resources-plugin</artifactId> 
      <version>2.7</version> 
      <dependencies> 
       <dependency> 
        <groupId>org.apache.maven.shared</groupId> 
        <artifactId>maven-filtering</artifactId> 
        <version>1.3</version> 
       </dependency> 
      </dependencies> 
     </plugin> 
    </plugins> 
    <resources> 
     <resource> 
      <targetPath>webapp</targetPath> 
      <directory>src/main/webapp</directory> 
     </resource> 
     <resource> 
      <directory>src/main/resources</directory> 
     </resource> 
    </resources> 
</build> 

これはmainクラスです:

public class TripMapServer { 

    private static final int DEFAULT_PORT = 8080; 
    private static final String CONTEXT_PATH = "/"; 
    private static final String MAPPING_URL = "/*"; 
    private static final String CONFIG_LOCATION = "com.biendltb.config"; 
    private static final String DEFAULT_PROFILE = "dev"; 

    public static void main(String[] args) throws Exception { 
     new TripMapServer().startJetty(getPortFromArgs(args)); 
    } 

    private static int getPortFromArgs(String[] args) { 
     if (args.length > 0) { 
      try { 
       return Integer.valueOf(args[0]); 
      } catch (NumberFormatException ignore) { 
      } 
     } 
     return DEFAULT_PORT; 
    } 

    private void startJetty(int port) throws Exception { 
     Server server = new Server(port); 
     server.setHandler(getServletContextHandler(getContext())); 
     server.start(); 
     server.join(); 
    } 

    private static ServletContextHandler getServletContextHandler(WebApplicationContext context) throws IOException { 
     ServletContextHandler contextHandler = new ServletContextHandler(); 
     contextHandler.setErrorHandler(null); 
     contextHandler.setContextPath(CONTEXT_PATH); 
     contextHandler.addServlet(new ServletHolder("default", new DispatcherServlet(context)), MAPPING_URL); 
     contextHandler.addEventListener(new ContextLoaderListener(context)); 
     contextHandler.setResourceBase(new ClassPathResource("webapp").getURI().toString()); 
     return contextHandler; 
    } 

    private static WebApplicationContext getContext() { 
     AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); 
     context.setConfigLocation(CONFIG_LOCATION); 
     context.getEnvironment().setDefaultProfiles(DEFAULT_PROFILE); 
     return context; 
    } 
} 

そして、これはクラスWebConfig.java代わり.xmlファイルです:

@Configuration 
@EnableWebMvc 
@Import({DefaultConfig.class}) 
@ComponentScan(basePackages = {"com.biendltb.controller"}) 
public class WebConfig extends WebMvcConfigurerAdapter{ 
    private static final Charset UTF8 = Charset.forName("UTF-8"); 

    @Autowired 
    public Environment env; 

    @Override 
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { 
     converters.add(stringConverter()); 
    } 

    private StringHttpMessageConverter stringConverter() { 
     StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(); 
     stringConverter.setSupportedMediaTypes(Arrays.asList(new MediaType("text", "plain", UTF8))); 
     return stringConverter; 
    } 

    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) { 
     registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/src/main/resources/").setCachePeriod(Integer.MAX_VALUE); 
     registry.addResourceHandler("/js/**").addResourceLocations("/js/").setCachePeriod(Integer.MAX_VALUE); 
     registry.addResourceHandler("/css/**").addResourceLocations("/css/").setCachePeriod(Integer.MAX_VALUE); 
     registry.addResourceHandler("/img/**").addResourceLocations("/img/").setCachePeriod(Integer.MAX_VALUE); 
    } 

    @Override 
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { 
     configurer.enable(); 
    } 

    @Bean 
    public InternalResourceViewResolver getInternalResourceViewResolver() { 
     InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 
     resolver.setPrefix("/src/main/resources/pages/"); 
     resolver.setSuffix(".jsp"); 
     return resolver; 
    } 
} 

原因を突き止めたり、そのエラーを追跡する方法を助けてください。

ありがとうございました!

答えて

0

実行時にクラスが欠落しています。 起動をデバッグし、NoClassDefFoundErrorに例外ブレークポイントを設定します。 クラスが見つからない場合があります。 IDEまたはWeb上のそのクラスを検索して、あなたの欠けている依存関係を見つけてください。

+0

こんにちはステファン、ModelAndViewを返すとき私のSpring Controllerで問題が発生しました。問題はSpringMVCの深いレベルにあるので、ここでtry catch例外を設定することができます。しかし、それはまた、明らかにエラーを理解していない。私は問題が私のSpringMVC構成にあるかもしれないと思う。とにかく、あなたの助けに感謝します:) – biendltb

+0

こんにちは、私は同じエラーを取得している、何があなたを助けた設定でしたか? – polavishnu

0

.m2フォルダをクリアすることをお勧めします。ダウンロード中にjarファイルの一部が破損することがあります。

あなたが役に立たなかったのであれば、是非コメントしてください!

+0

アドバイスいただきありがとうございますが、それでも私の問題を解決することはできません:( – biendltb

関連する問題