org.springframework.boot.web.support不存在 [英] org.springframework.boot.web.support does not exist

查看:1315
本文介绍了org.springframework.boot.web.support不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将构建系统从Maven更改为Gradle,以实现Spring引导项目。我得到这个堆栈跟踪

  19:03:08:执行外部任务'bootRun'... 
/ home / / java / sample / jetty / jsp / SampleJettyJspApplication.java:22:error:package org.springframework / java / sample / jetty / jsp / SampleJettyJspApplication.java:22:error:package org.springframework .boot.web.support不存在
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:can not 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:方法不会覆盖或实现来自超类型$ b的方法$ b @Override
^
3错误
:compileJava失败

失败:生成失败,出现异常。

*出错:
任务'compileJava'的执行失败。
>编译失败;详细信息请参阅编译器错误输出。

*尝试:
使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。

构建失败

总时间:2.334秒
编译失败;详细信息请参阅编译器错误输出。
19:03:10:外部任务执行完成'bootRun'。

我的 build.gradle

  buildscript {
repositories {
mavenCentral()
}
依赖关系{
classpathorg.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'
应用插件:'rebel'

buildscript {
repositories {
mavenCentral()
}

依赖项{
classpath组:'org.zeroturnaround',名称:'gradle-jrebel-plugin',版本:'1.1.3'
}
}
jar {
baseName ='gs-spring -boot'
version ='0.1.0'
}

储存库{
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

依赖项{
// tag :: jetty []
compile(org.springframework.boot:spring-boot-starter-web){
排除模块: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)

}

//更改默认的IntelliJ输出目录以编译类
idea {
module {
inheritOutputDirs = false
outputDir = file($ buildDir / classes / main /)
}
}

任务包装(类型:包装){
gradleVersion ='2.3'
}

我的 pom.xml

 < ;? xml version =1.0encoding =UTF-8?> 
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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>
<! - 你自己的应用程序应该继承自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>
< name> Spring Boot Jetty JSP示例< / name>
< description> Spring Boot Jetty JSP示例< / description>
< url> http://projects.spring.io/spring-boot/< / url>
< organization>
<名称> Pivotal Software,Inc.< / name>
< url> http://www.spring.io< / url>
< / organization>
<属性>
$ {basedir} /../..& lt; /main.basedir>
< m2eclipse.wtp.contextRoot> /< /m2eclipse.wtp.contextRoot>
< / properties>
<依赖关系>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
<排除项>
<排除>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-tomcat< / artifactId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-validation< / artifactId>
<排除项>
<排除>
< groupId> org.apache.tomcat.embed< / groupId>
< artifactId> tomcat-embed-el< / artifactId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-jetty< / artifactId>
<! - < scope>提供< / scope> - >
< /依赖关系>
< dependency>
< groupId> javax.servlet< / groupId>
< artifactId> jstl< / artifactId>
< /依赖关系>
< dependency>
< groupId> org.eclipse.jetty< / groupId>
< artifactId> apache-jsp< / artifactId>
<! - < scope>提供< / scope> - >
< /依赖关系>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-test< / artifactId>
< scope> test< / scope>
< /依赖关系>
< /依赖关系>
< build>
< plugins>
< plugin>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-maven-plugin< / artifactId>
<配置>
< executable> true< / executable>
< / configuration>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-surefire-plugin< / artifactId>
<配置>
< useSystemClassLoader> false< / useSystemClassLoader>
< / configuration>
< / plugin>



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

我应该如何让包可用于gradle?



  org.springframework.boot.context.web.SpringBootServletInitializer 

然而,您的Maven pom.xml使用Spring Boot 1.4.0.BUILD-SNAPSHOT,其中包名称已更改为:

  org.springframework.boot.web.support.SpringBootServletInitializer 



<因此,如果您转到SampleJettyJspApplication并将导入更改为

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

一切都应该没问题。

或者,您可以修改Gradle构建脚本以导入1.4.0.BUILD-SNAPSHOT,但这需要添加Spring的快照存储库:

  buildscript {
存储库{
maven.urlhttp://repo.spring.io/snapshot
mavenCentral ()
}

依赖关系{
classpath(org.springframework.boot:spring-boot-gradle-plugin:1.4.0.BUILD-SNAPSHOT)
}
}


I'm changing build systems from maven to gradle for a spring boot project. I get this stacktrace

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'.

My 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'
}

My 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>

How should I make the package available to gradle?

解决方案

It's probably an import issue in your source code - your Gradle build script uses Spring Boot 1.3.6.RELEASE in which SpringBootServletInitializer has the following fully qualified name:

org.springframework.boot.context.web.SpringBootServletInitializer 

Your Maven pom.xml, however, uses Spring Boot 1.4.0.BUILD-SNAPSHOT, in which the package name was changed to:

org.springframework.boot.web.support.SpringBootServletInitializer

So if you go to your SampleJettyJspApplication and change the import to

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

everything should be fine.

Alternatively, you could alter your Gradle build script to import 1.4.0.BUILD-SNAPSHOT, but that would require adding Spring's snapshot repository:

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

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

这篇关于org.springframework.boot.web.support不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆