问题
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>
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/32941815/spring4-failed-to-read-candidate-component-class-couchbaseconfig-class