Oleg Tsal-Tsalko
Oleg Tsal-Tsalko

Reputation: 225

Spring Data Rest Boot app fails to start with Java config class

I'm trying to run simple Spring Data Rest Boot app (v1.2.3.RELEASE) with only one small modification from working Spring reference example app (http://spring.io/guides/gs/accessing-mongodb-data-rest/) and it failed to start.

To be more specific when I use:

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

and just following simple code configuration:

public class Application {
    public static void main(String[] args){
        SpringApplication.run(Config.class, args);
    }
}

@SpringBootApplication
public class Config {
}

without anything else I'm getting following error on startup:

2015-04-20 12:07:32.250 ERROR 5693 --- [ main] o.s.boot.SpringApplication : Application startup failed

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat ...

Caused by: java.lang.ClassCastException: jug.ua.json.test.Config$$EnhancerBySpringCGLIB$$79797226 cannot be cast to org.springframework.data.rest.core.config.RepositoryRestConfiguration at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$3a999d99.config() ...

However following code configuration is working fine:

@SpringBootApplication
public class Application {
    public static void main(String[] args){
        SpringApplication.run(Application.class, args);
    }
}

Also if instead I use:

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

separate Java config class approach is working fine as well...

What I'm doing wrong, cause I can't believe I spotted such an obvious bug?

Thank you, Oleg

Upvotes: 0

Views: 4535

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116051

The problem appears to be due to a name clash between the config bean method on SpringBootRepositoryRestMvcConfiguration (inherited from Spring Data REST's RepositoryRestMvcConfiguration) and your configuration class named Config. Renaming it to something other than Config should get things working again.

Upvotes: 5

Related Questions