4

I have a problem. I'm using Spring4 and i want to add a configuration to be able to use spring data couchbase and i have an error :

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/home/charlie/Desktop/Ultimate Projects/novare_dashboard/novare-project-dashboard/target/classes/hk/com/novare/dashboard/configuration/CouchbaseConfig.class]; nested exception is java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories.repositoryBaseClass() at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:303)

Here is my code:

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

    <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>
Arpit Aggarwal
  • 27,626
  • 16
  • 90
  • 108
ButchxD
  • 71
  • 1
  • 8

2 Answers2

0

Can see the error for missing repositoryBaseClass config which is needed to create the repository proxies for your CouchbaseConfig class :-

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

Pls specify same as parameter to @EnableCouchbaseRepositories

Avis
  • 2,197
  • 18
  • 28
  • I also tried it before basePackages and baseClassesPackage but still the same . – ButchxD Oct 05 '15 at 06:09
  • org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/home/charlie/Desktop/Ultimate Projects/novare_dashboard/novare-project-dashboard/target/classes/hk/com/novare/dashboard/configuration/CouchbaseConfig.class]; nested exception is java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories.repositoryBaseClass() *I also add parameter but still the same @EnableCouchbaseRepositories(basePackages = "hk.com.novare.dashboard") – ButchxD Oct 05 '15 at 06:24
  • Have you defined any interface with @Repository within that package which extends CouchbaseConfig ?? – Avis Oct 05 '15 at 06:27
  • @Repository public interface PersonRepository extends CrudRepository { } **Here is my PersonRepository Class. I import this: -> import org.springframework.data.repository.CrudRepository; – ButchxD Oct 05 '15 at 06:33
  • It seems the issue is something else which is ending up showing these trails. Is your couchbase DB up & running while you were testing !!! Also i see you have h2 library in your pom, can you clean it as well and check. – Avis Oct 05 '15 at 06:49
  • I have h2 library in POM as shown above. Yap couchbase db is running in my local – ButchxD Oct 05 '15 at 06:55
  • Could be some library version mismatch as well. Can you try changing the couchbase client version from 1.4.9 to 1.4.7 – Avis Oct 05 '15 at 07:27
  • I got still the same error.. when i change the version of spring data couchbase to 1.2.2 the error changed to "Injection of autowired dependencies failed; nested exception is" Btw Thanks for helping me. – ButchxD Oct 05 '15 at 07:36
  • 1
    Use spring data couchbase 1.2.2 and remove the @Repository on your repository and it will works fine. – ButchxD Oct 24 '15 at 05:13
0

I just found a solution regarding my error. You must change your spring-data-couchbase version to 1.2.2 and remove the annotation @Repository to your repository.

ButchxD
  • 71
  • 1
  • 8