1
votes

I work with Spring but never tried Spring Boot. I wanted to try the accessing-data-jpa tutorial - https://spring.io/guides/gs/accessing-data-jpa/. I have cloned the repository from git and run it with Maven as described in the tutorial: git clone https://github.com/spring-guides/gs-accessing-data-jpa.git mvnw spring-boot:run

Running this, I got an error - Caused by: java.lang.ClassNotFoundException: org.springframework.data.repository.CrudRepository

To solve this, I have added a dependency:

<dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons-core</artifactId>
            <version>1.4.1.RELEASE</version>
        </dependency>

This helped, however, i got another error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method demo in hello.Application required a bean of type 'hello.CustomerRepository' that could not be found.


Action:

Consider defining a bean of type 'hello.CustomerRepository' in your configuration.

[WARNING]

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:527)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demo' defined in hello.Application: Unsatisfied dependency expressed through method 'demo' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'hello.CustomerRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
        at hello.Application.main(Application.java:17)
        ... 6 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'hello.CustomerRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
        at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
        ... 24 more

I am surprised that an official tutorial from Spring does not work. Have you tried this tutorial? Do you have any suggestion why it does not work? Is it broken or is something wrong on my machine? As I know little about Spring Boot I'm not really sure what the problem may be.

1
If you followed the tutorial and it didn't work, raise an issue on the repo. Is it the same as github.com/spring-guides/gs-accessing-data-jpa/issues/20? - jonrsharpe
suppose you can get started with Spring boot from here - Rajith Pemabandu
git clone https://github.com/spring-guides/gs-accessing-data-jpa spj, followed by cd spj/complete, followed by mvn spring-boot:run works perfectly fine for me. How are you trying to run the sample? - manish
Thanks for suggestions - i have changed the version of Spring Data and deleted my Maven repository completely. After this, the tutorial started to work. My Maven repository must have been corrupted somehow. I just did not realise, it could be the problem. - Ondřej

1 Answers

0
votes

It turned out my Maven repository was corrupted. Deleting it and downloading fresh copies of everything has helped. The tutorial runs.