简体   繁体   English

找不到主要/资源中的类

[英]Class in main/resources not found

I'm using the Spring Boot gradle plugin to build an executable war. 我正在使用Spring Boot gradle插件来构建可执行文件。 I have a FindResource.java class in src/main/resources to locate files: 我在src / main / resources中有一个FindResource.java类来查找文件:

FindResource.class.getResource(templateName).toURI()

When I execute gradle build I get an error, that the class FindResource cannot be resolved. 当我执行gradle build时,我得到一个错误,该类FindResource无法解析。 Do I need to the the Spring Boot gradle plugin, that it should also use classes from the resources directory. 我需要Spring Boot gradle插件吗,它还应该使用resources目录中的类。 How can I do so? 我该怎么办?

My build.gradle looks as follows: 我的build.gradle如下所示:

buildscript {
    ext {
        springBootVersion = '1.2.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
        classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot' 
apply plugin: 'io.spring.dependency-management' 

jar {
    baseName = 'abc'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-jersey")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.apache.pdfbox:pdfbox:1.8.10")
    compile('org.apache.poi:poi-ooxml:3.12')
    compile('org.apache.poi:poi-scratchpad:3.12')
    runtime("org.hsqldb:hsqldb")
    testCompile("org.springframework.boot:spring-boot-starter-test") 
}


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

As mentioned in the comment class files to load need to be in src/main/java/ and not in src/main/resources. 如注释类中所述,要加载的文件必须位于src / main / java /中,而不是src / main / resources中。 This link may help give you more information on the convention of this structure. 该链接可以帮助您提供有关此结构约定的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM