2016-07-16 113 views
9

Sto cambiando i sistemi di costruzione da Maven a Gradle per un progetto di avvio a molla. Ottengo questo stacktraceorg.springframework.boot.web.support non esiste

19:03:08: Executing external task 'bootRun'... 
/home/dac/proj/spring-boot-master/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/SampleJettyJspApplication.java:22: error: package org.springframework.boot.web.support does not exist 
import org.springframework.boot.web.support.SpringBootServletInitializer; 
             ^
/home/dac/proj/spring-boot-master/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/SampleJettyJspApplication.java:25: error: cannot find symbol 
public class SampleJettyJspApplication extends SpringBootServletInitializer { 
              ^
    symbol: class SpringBootServletInitializer 
/home/dac/proj/spring-boot-master/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/SampleJettyJspApplication.java:27: error: method does not override or implement a method from a supertype 
    @Override 
    ^
3 errors 
:compileJava FAILED 

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':compileJava'. 
> Compilation failed; see the compiler error output for details. 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

BUILD FAILED 

Total time: 2.334 secs 
Compilation failed; see the compiler error output for details. 
19:03:10: External task execution finished 'bootRun'. 

mio build.gradle

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath "org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE" 
     classpath 'org.springframework:springloaded:1.2.5.RELEASE' 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'idea' 
apply plugin: 'spring-boot' 
apply plugin: 'rebel' 

buildscript { 
    repositories { 
     mavenCentral() 
    } 

    dependencies { 
     classpath group: 'org.zeroturnaround', name: 'gradle-jrebel-plugin', version: '1.1.3' 
    } 
} 
jar { 
    baseName = 'gs-spring-boot' 
    version = '0.1.0' 
} 

repositories { 
    mavenCentral() 
} 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

dependencies { 
    // tag::jetty[] 
    compile("org.springframework.boot:spring-boot-starter-web") { 
     exclude module: "spring-boot-starter-tomcat" 
    } 
    compile("org.springframework.boot:spring-boot-starter-jetty") 
    // end::jetty[] 
    // tag::actuator[] 
    compile("org.springframework.boot:spring-boot-starter-actuator") 

    testCompile("org.springframework.boot:spring-boot-starter-test") 
    testCompile("junit:junit") 

} 

// change default IntelliJ output directory for compiling classes 
idea { 
    module { 
     inheritOutputDirs = false 
     outputDir = file("$buildDir/classes/main/") 
    } 
} 

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

mio 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> 
    <parent> 
     <!-- Your own application should inherit from spring-boot-starter-parent --> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-samples</artifactId> 
     <version>1.4.0.BUILD-SNAPSHOT</version> 
    </parent> 
    <artifactId>spring-boot-sample-jetty-jsp</artifactId> 
    <packaging>war</packaging> 
    <name>Spring Boot Jetty JSP Sample</name> 
    <description>Spring Boot Jetty JSP Sample</description> 
    <url>http://projects.spring.io/spring-boot/</url> 
    <organization> 
     <name>Pivotal Software, Inc.</name> 
     <url>http://www.spring.io</url> 
    </organization> 
    <properties> 
     <main.basedir>${basedir}/../..</main.basedir> 
     <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
      <exclusions> 
       <exclusion> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-tomcat</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-validation</artifactId> 
      <exclusions> 
       <exclusion> 
        <groupId>org.apache.tomcat.embed</groupId> 
        <artifactId>tomcat-embed-el</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-jetty</artifactId> 
      <!--<scope>provided</scope>--> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>jstl</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>apache-jsp</artifactId> 
      <!--<scope>provided</scope>--> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
       <configuration> 
        <executable>true</executable> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <configuration> 
        <useSystemClassLoader>false</useSystemClassLoader> 
       </configuration> 
      </plugin> 



     </plugins> 
    </build> 
</project> 

Come dovrei rendere il pacchetto disponibile per Gradle?

+0

Perché entrambi, esperto e gradle? Usa l'uno o l'altro non entrambi. –

+0

Poiché questo è un difetto di un file sorgente Java, un IDE intelligente può essere in grado di dirti esattamente come risolverlo: fare clic-clic-fatto. Codice di Visual Studio ha fatto questo per me per risolvere questo errore. – nobar

risposta

7

è probabilmente un problema di importazione nel vostro codice sorgente - la vostra Gradle costruire script utilizza Primavera di avvio 1.3.6.RELEASE in cui SpringBootServletInitializer ha il seguente nome completo:

org.springframework.boot.context.web.SpringBootServletInitializer 

tuo Maven pom.xml, tuttavia , utilizza Primavera Boot 1.4.0.BUILD-SNAPSHOT, in cui il nome del pacchetto è stato cambiato in:

org.springframework.boot.web.support.SpringBootServletInitializer 

Quindi, se si va al SampleJettyJspApplication e cambiare l'importazione

import org.springframework.boot.context.web.SpringBootServletInitializer; 

tutto dovrebbe andare bene.

alternativa, è possibile modificare la vostra Gradle costruire script per importare 1.4.0.BUILD-SNAPSHOT, ma che richiederebbe l'aggiunta di repository snapshot di Primavera:

buildscript { 
    repositories { 
     maven.url "http://repo.spring.io/snapshot" 
     mavenCentral() 
    } 

    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.BUILD-SNAPSHOT") 
    } 
} 
+1

Grazie amico. Dove ha menzionato Spring nel doc? – Adnan

+1

"Tutte le classi nel pacchetto org.springframework.boot.context.web sono state deprecate e trasferite." https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes#deprecations-in-spring-boot-14 –

3

si dovrebbe utilizzare la versione di boot stessa sorgente 1.4.0 .BUILD-SNAPSHOT come in Maven. org.springframework.boot.web.support.SpringBootServletInitializer è stato introdotto a partire dalla 1.4.0 ed è per questo che il gradle non riesce a trovarlo.

+1

Non ho aggiunto la dipendenza 'classpath" org. springframework.boot: spring-boot-gradle-plugin: 1.4.0.BUILD-SNAPSHOT "' gradle non può riconfigurare –

+0

Questo perché 1.4.0.BUILD-SNAPSHOT si trova solo nel repository di snapshot di Spring e non nel Maven centrale, prendi un guarda la mia risposta per un esempio di codice. –

+1

Aggiungi spring repos to gradle come suggerito da @ Miloš. Documentazione sul plugin Spring Boot Gradle http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/build-tool-plugins-gradle-plugin.html –