我有个问题。我正在使用Spring4,我想添加一个配置以能够使用Spring Data Couchbase,但是我遇到了一个错误:


org.springframework.beans.factory.BeanDefinitionStoreException:无法读取候选组件类:文件
[/ home / charlie / Desktop / Ultimate
项目/novare_dashboard/novare-project-dashboard/target/classes/hk/com/novare/dashboard/configuration/CouchbaseConfig.class];
嵌套异常是java.lang.annotation.AnnotationFormatError:
无效的默认值:public abstract java.lang.Class
org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories.repositoryBaseClass()

org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:303)


这是我的代码:

CouchbaseConfig.java

@Configuration
@EnableCouchbaseRepositories
public class CouchbaseConfig extends AbstractCouchbaseConfiguration{

@Override
protected List<String> bootstrapHosts() {
    return Collections.singletonList("localhost");
}

@Override
protected String getBucketName() {
    return "crud";
}

@Override
protected String getBucketPassword() {
    return "password";
}}


WebMvcConfig.java

@Configuration
@EnableWebMvc
@ComponentScan(basePackageClasses = Application.class)
public class WebMvcConfig extends WebMvcConfigurerAdapter {

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

@Bean
public InternalResourceViewResolver jspViewResolver() {
    InternalResourceViewResolver bean = new InternalResourceViewResolver();
    bean.setPrefix("/WEB-INF/views/");
    bean.setSuffix(".jsp");
    return bean;
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/static/**").addResourceLocations("/WEB-INF/static/");
}}


POM文件



    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!--H2-->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!--couchbase-->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-couchbase</artifactId>
        <version>1.4.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.couchbase.client</groupId>
        <artifactId>couchbase-client</artifactId>
        <version>1.4.9</version>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>3.0</version>
    </dependency>

    <!--JSON-->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

</dependencies>

最佳答案

可以看到缺少为您的CouchbaseConfig类创建存储库代理所需的repositoryBaseClass配置错误的错误:

nested exception is java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class
org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories.repositoryBaseClass() at


请指定与@EnableCouchbaseRepositories的参数相同的参数

07-26 09:42