I want get a response from client service with Spring cloud FeignClint I wrote a FeignClient interface
#FeignClient(name = "currencyClient", url = "https://example", configuration = FeignConfig.class)
public interface CurrencyClient {
#RequestLine(value = "GET /{name}/{date}")
#Headers("Content-Type: application/json")
Currency getByNameAndDate(#Param String name, #Param LocalDateTime date);
}
But it is not compiling this error is occuring
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uz.md.shopapp.controller.client.CurrencyClient': FactoryBean threw exception on object creation
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:154) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:90) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1823) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1265) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:259) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1628) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1585) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1368) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1325) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) ~[spring-beans-6.0.4.jar:6.0.4]
... 38 common frames omitted
Caused by: java.lang.IllegalStateException: Method CurrencyClient#getByNameAndDate(String,LocalDateTime) not annotated with HTTP method type (ex. GET, POST)
Warnings:
-
at feign.Util.checkState(Util.java:136) ~[feign-core-12.1.jar:na]
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:115) ~[feign-core-12.1.jar:na]
at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:193) ~[spring-cloud-openfeign-core-4.0.1.jar:4.0.1]
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:65) ~[feign-core-12.1.jar:na]
at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:142) ~[feign-core-12.1.jar:na]
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:58) ~[feign-core-12.1.jar:na]
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:50) ~[feign-core-12.1.jar:na]
at feign.Feign$Builder.target(Feign.java:197) ~[feign-core-12.1.jar:na]
at org.springframework.cloud.openfeign.DefaultTargeter.target(DefaultTargeter.java:30) ~[spring-cloud-openfeign-core-4.0.1.jar:4.0.1]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:470) ~[spring-cloud-openfeign-core-4.0.1.jar:4.0.1]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:421) ~[spring-cloud-openfeign-core-4.0.1.jar:4.0.1]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:148) ~[spring-beans-6.0.4.jar:6.0.4]
You should try the annotations #PathVariable and the #GetMapping instead
#GetMapping(path = "/{name}/{date}")
Currency getByNameAndDate(#PathVariable String name, #PathVariable LocalDateTime date);
This is how the client should be set up:
public interface CurrencyClient {
#RequestMapping(method = RequestMethod.GET, value = "/{name}/{date}")
#Headers("Content-Type: application/json")
List<Store> getByNameAndDate(#PathVariable("name") String name, #PathVariable("date") Date date);
}
Related
I have a small spring-boot application, where I am trying to pickup properties from application.properties into my #Component class.
However, I get the following error
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bucket4jRateLimiterV2' defined in file [/Users/npatira/Documents/workspace-spring-tool-suite-4-4.15.3.RELEASE/assessment/target/classes/com/nishit/ninesixteen/listener/Bucket4jRateLimiterV2.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.nishit.ninesixteen.listener.Bucket4jRateLimiterV2]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: 0 is wrong value for period tokens, because tokens should be positive
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1232)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656)
... 34 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.nishit.ninesixteen.listener.Bucket4jRateLimiterV2]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: 0 is wrong value for period tokens, because tokens should be positive
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326)
... 45 common frames omitted
Caused by: java.lang.IllegalArgumentException: 0 is wrong value for period tokens, because tokens should be positive
at io.github.bucket4j.BucketExceptions.nonPositivePeriodTokens(BucketExceptions.java:106)
at io.github.bucket4j.Refill.<init>(Refill.java:46)
at io.github.bucket4j.Refill.intervally(Refill.java:108)
at com.nishit.ninesixteen.listener.Bucket4jRateLimiterV2.<init>(Bucket4jRateLimiterV2.java:24)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
... 47 common frames omitted
My interpretation of this error is that it has not been able to pick up either the value from application.properties or the default value assigned.
Below is the code for the Component.
#Component
public class Bucket4jRateLimiterV2 {
#Value("${ratelimit:100}")
private int throttleRate;
#Value("${thrrotleDuration:1}")
private int refillDuration;
private Refill refill;
private Bandwidth limit;
private Bucket BUCKET;
public Bucket4jRateLimiterV2() {
System.out.println("Values are : " + throttleRate + " " + refillDuration);
refill = Refill.intervally(throttleRate, Duration.ofMinutes(refillDuration));
limit = Bandwidth.classic(5, refill);
BUCKET = Bucket4j.builder().addLimit(limit).build();
}
public boolean isAPICallAllowed() {
System.out.println("thrrotleRate : " + throttleRate);
System.out.println("Available tokens are : " + BUCKET.getAvailableTokens() + " called from thread : "
+ Thread.currentThread().getName());
return BUCKET.tryConsume(TOKEN_COUNT);
}
}
This gave an output
Values are : 0 0
which means the int were initialized without picking up the value from the properties file.
and this is how my application.properties looks
ratelimit = 500
throttleDuration = 1
My main class has the following annotations.
#EnableAsync
#SpringBootApplication
#ComponentScan(basePackages = "com.nishit")
#EnableCaching(proxyTargetClass = true)
What have I tried?
I first thought that application.properties is not in my classpath. Verified that.
I tried #Component, #Service, #Controller in all these annotations, to see if the property gets picked up somewhere.
Any idea of what it is that I have done wrong?
try,This works with here as well.
When I try to autowire MicrometerRegistry to a class containing KafkaListener, I get the following error -
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaConsumer' defined in file [/apps/flux-mariadb-pipeline/build/classes/java/main/com/processor/consumer/KafkaConsumer.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.processor.consumer.KafkaConsumer]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:313)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:294)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.processor.App.main(App.java:10)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.processor.consumer.KafkaConsumer]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:217)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:309)
... 20 common frames omitted
Caused by: java.lang.NullPointerException: null
at java.util.Objects.requireNonNull(Objects.java:203)
at io.micrometer.core.instrument.ImmutableTag.<init>(ImmutableTag.java:35)
at io.micrometer.core.instrument.Tag.of(Tag.java:29)
at io.micrometer.core.instrument.Tags.and(Tags.java:74)
at io.micrometer.core.instrument.Timer$Builder.tag(Timer.java:364)
at com.processor.consumer.KafkaConsumer.<init>(KafkaConsumer.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:204)
... 22 common frames omitted
KafkaConsumer class -
public KafkaConsumer(MeterRegistry meterRegistry) {
eventTimer =
Timer.builder("travel.time")
.description("The time it takes for the event to travel.")
.tag("topic", topic)
.publishPercentiles(.30, .65, .99)
.publishPercentileHistogram()
.minimumExpectedValue(Duration.ofMillis(1))
.maximumExpectedValue(Duration.ofMillis(5000))
.register(meterRegistry);
}
#KafkaListener(
topics = "${spring.kafka.consumer.properties.topic}",
groupId = "${spring.kafka.consumer.group-id}")
public void consume(
ConsumerRecord<String, DataRecord> record,
#Header(KafkaHeaders.RECEIVED_PARTITION_ID) Integer partition,
#Header(KafkaHeaders.OFFSET) Long offset,
Acknowledgment ack)
throws IOException {
.
.
}
I am creating KafkaListener container using the factory as below -
#Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>>
kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, String> factory =
new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
factory.setConcurrency(8);
factory.getContainerProperties().setAckMode(AckMode.MANUAL_IMMEDIATE);
factory.setErrorHandler(getErrorHandler());
return factory;
}
Only way I found to add micrometer registry is like below
#Bean public ConsumerFactory<String, String> consumerFactory() {
Map<String, Object> props = kafkaProperties.buildConsumerProperties();
DefaultKafkaConsumerFactory<String, String> cf = new DefaultKafkaConsumerFactory<>(props);
cf.addListener(new MicrometerConsumerListener<>(meterRegistry(),
Collections.singletonList(new ImmutableTag("customTag", "customTagValue"))));
return cf;
}
Now, I do not know how to access this registry inside the #KafkaListener method
at io.micrometer.core.instrument.ImmutableTag.(ImmutableTag.java:35)
.tag("topic", topic)
The topic variable is null.
If it has a #Value annotation, you can't use it in the constructor; create the meter in an #PostConstruct method instead.
How to get the JobId in the SkipListener? I used below logic but its not working.
private Long jobId;
#BeforeStep
public void getJobId(StepExecution stepExecution) {
this.jobId = stepExecution.getJobExecution().getJobId();
}
I also tried below
#Value("#{stepExecution.jobExecution.jobId}")
private Long jobId;
But getting the below
Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'stepExecution' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:164) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1569) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1250) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
... 85 common frames omitted
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'stepExecution' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217) ~[spring-expression-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104) ~[spring-expression-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:91) ~[spring-expression-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:55) ~[spring-expression-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:91) ~[spring-expression-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:112) ~[spring-expression-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:272) ~[spring-expression-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:161) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
... 89 common frames omitted
The first approach (implementing the SkipListener interface) should work with adding step scope. The second approach (injecting the stepExecution using a SpEL expression) requires the listener to be declared as a step scoped bean.
Is this fine if we define reader bean with the StepScope and not the processor and writer beans? Please confirm
Yes that's ok. Not all step components need to be step-scoped together.
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'myname' in value "${myname}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:908) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1228) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:636) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:397) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
... 94 common frames omitted
#Value("${myName}")
private String myName
myName is value getting readed from Vault, with old Spring boot version it was worked well, Issue started after Latest upgrade
And Test Case fail with
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'linkDiscoverers' defined in class path resource [org/springframework/hateoas/config/HateoasConfigurati
on.class]: Unsatisfied dependency expressed through method 'linkDiscoverers' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.s
pringframework.plugin.core.PluginRegistry<org.springframework.hateoas.client.LinkDiscoverer, org.springframework.http.MediaType>' available: expected single matching bean but found 3: relProviderPluginRegistry,
linkDiscovererRegistry,entityLinksPluginRegistry
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.plugin.core.PluginRegistry<org.springframework.hateoas.client.LinkDiscoverer, org.sp
ringframework.http.MediaType>' available: expected single matching bean but found 3: relProviderPluginRegistry,linkDiscovererRegistry,entityLinksPluginRegistry
This might help you, I have created a vault configuration class, and I am putting my credential like below
vault kv put secret/gs-vault-config app.security.username=myUser
app.security.password=myPassword
Now wherever I want to use my vault property I inject vault configuration class
#Autowired
private VaultConfiguration vault;
then the required properties can be accessed from getter method, and below is my VaultConfiguration
#ConfigurationProperties("app.security")
public class VaultConfiguration {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Also, you need to enable configuration properties, I added below annotation on my Application class
#SpringBootApplication
#EnableConfigurationProperties(VaultConfiguration.class)
public class Application { ..... }
I am having the following error while running my Spring Application:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleController' defined in file [/home/john/Documents/Projects/lottery-api/target/classes/io/sunbits/lotteryapi/resources/RoleController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleService' defined in file [/home/john/Documents/Projects/lottery-api/target/classes/io/sunbits/lotteryapi/services/RoleService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract io.sunbits.lotteryapi.entities.User io.sunbits.lotteryapi.data.repository.ExtendedCrudRepository.findOne(java.lang.Long)! No property findOne found for type Role!
The application is pretty big, so I will copy paste you the code related to RoleController.class and maybe you can help me :).
RoleController:
#CrossOrigin
#RestController
#RequestMapping(value = "/roles",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
public class RoleController {
private RoleService service;
#Autowired
public RoleController(RoleService service) {
this.service = service;
}
#RequestMapping(value = "", method = RequestMethod.GET, consumes = MediaType.ALL_VALUE)
#ResponseStatus(value = HttpStatus.CREATED)
public ResponseEntity<?> search(
#RequestParam(required = false) String name,
#RequestParam(required = false) String description,
#RequestParam(required = false) Boolean active,
#RequestParam(value = "_page", defaultValue = "0", required = false) Integer page,
#RequestParam(value = "_size", defaultValue = "25", required = false) Integer size,
#RequestParam(value = "_sort", defaultValue = "-name", required = false) String sort) {
Pageable pageable = new PageRequest(page, size,
SortUtils.processSort(
sort,
new String[]{"name","description","active"}
));
Specification specification = RoleSpecification.genericSearchSpecification(name,description,active);
Page<Role> roles = this.service.findAll(specification,pageable);
PageInfo pageInfo = new PageInfo(roles);
return ResponseEntity.ok(new RestResponse<>(roles.getContent(),pageInfo));
}
#RequestMapping(value = {"", "/"}, method = RequestMethod.POST)
#ResponseStatus(value = HttpStatus.CREATED)
//#PreAuthorize("#oauth2.hasRole('create_item')")
public ResponseEntity<?> create(#Valid #RequestBody Role role, BindingResult result, HttpServletRequest request) {
if (result.hasErrors()) {
return new ResponseEntity<>(result.getFieldErrors(), HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(this.service.create(role), HttpStatus.CREATED);
}
#RequestMapping(value = "/{id}", method = RequestMethod.GET, consumes = MediaType.ALL_VALUE)
#ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<?> find(#PathVariable Long id) {
Role role = service.findOne(id);
ApiPreconditions.assertNotNullOrEmpty(role, "Role not exists: " + id);
return ResponseEntity.ok(role);
}
#RequestMapping(value = "/{id}", method = RequestMethod.PUT)
#ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<?> update(#PathVariable Long id, #RequestBody Role role) {
Role oldRole = service.findOne(id);
ApiPreconditions.assertNotNullOrEmpty(oldRole, "Role not exists: " + id);
// Update user id
oldRole.setDescription(role.getDescription());
oldRole.setName(role.getName());
oldRole.setActive(role.getActive());
oldRole.setPermissions(role.getPermissions());
return ResponseEntity.ok(service.update(oldRole));
}
#RequestMapping(value = "/{id}", method = RequestMethod.DELETE, consumes = MediaType.ALL_VALUE)
#ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<?> delete(#PathVariable Long id) {
Role oldRole = service.findOne(id);
ApiPreconditions.assertNotNullOrEmpty(oldRole, "Role not exists: " + id);
// Delete the user
service.delete(oldRole);
return ResponseEntity.ok(oldRole);
}
}
RoleRepository
#Repository
public interface RoleRepository extends ExtendedCrudRepository<Role, Long> {
Set<Role> findByUsersAndActive(User user, Boolean active);
Role findByName(String name);
}
RoleService:
#Service
public class RoleService {
private RoleRepository repository;
private PermissionService permissionService;
#Autowired
public RoleService(RoleRepository repository, PermissionService permissionService) {
this.repository = repository;
this.permissionService = permissionService;
}
public Set<Role> findActiveRolesForUser(User user) {
Set<Role> roles = repository.findByUsersAndActive(user, true);
if (roles != null && roles.size() > 0) {
Set<Permission> permissions;
for (Role role : roles) {
permissions = permissionService.findActivePermissionForRole(role);
role.setPermissions(permissions != null ? permissions : new HashSet<>());
}
}
return roles;
}
public Role findOne(Long id) {
return repository.getOne(id);
}
public Page<Role> findAll(Specification specification, Pageable pageable) {
return getRepository().findAll(specification, pageable);
}
public RoleRepository getRepository() {
return repository;
}
public Role create(Role role) {
return repository.save(role);
}
public Role update(Role oldRole) {
this.repository.save(oldRole);
return oldRole;
}
public void delete(Role oldRole) {
}
}
I would appreciate if you can help me find the issue :). If you need more details please let me know.
Edit: I will also add ExtendedCrudRepository
#NoRepositoryBean
public interface ExtendedCrudRepository<T, ID extends Serializable> extends JpaRepository<T, ID>,
JpaSpecificationExecutor<T> {
User findOne(Long id);
void deleteById(User oldUser);
}
Edit 2: I will add Stacktrace since the error begins:
2018-03-28 16:25:18.252 INFO 9330 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#77d0dbba'
2018-03-28 16:25:18.255 INFO 9330 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-03-28 16:25:19.182 WARN 9330 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleController' defined in file [/home/john/Documents/Projects/lottery-api/target/classes/io/sunbits/lotteryapi/resources/RoleController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleService' defined in file [/home/john/Documents/Projects/lottery-api/target/classes/io/sunbits/lotteryapi/services/RoleService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.lang.Object io.sunbits.lotteryapi.data.repository.ExtendedCrudRepository.findOne(java.io.Serializable)! No property findOne found for type Role!
2018-03-28 16:25:19.183 INFO 9330 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-03-28 16:25:19.184 INFO 9330 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2018-03-28 16:25:19.205 INFO 9330 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2018-03-28 16:25:19.206 INFO 9330 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-03-28 16:25:19.230 INFO 9330 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-03-28 16:25:19.235 ERROR 9330 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleController' defined in file [/home/john/Documents/Projects/lottery-api/target/classes/io/sunbits/lotteryapi/resources/RoleController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleService' defined in file [/home/john/Documents/Projects/lottery-api/target/classes/io/sunbits/lotteryapi/services/RoleService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.lang.Object io.sunbits.lotteryapi.data.repository.ExtendedCrudRepository.findOne(java.io.Serializable)! No property findOne found for type Role!
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at io.sunbits.lotteryapi.LotteryapiApplication.main(LotteryapiApplication.java:12) [classes/:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleService' defined in file [/home/john/Documents/Projects/lottery-api/target/classes/io/sunbits/lotteryapi/services/RoleService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.lang.Object io.sunbits.lotteryapi.data.repository.ExtendedCrudRepository.findOne(java.io.Serializable)! No property findOne found for type Role!
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:721) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
... 19 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.lang.Object io.sunbits.lotteryapi.data.repository.ExtendedCrudRepository.findOne(java.io.Serializable)! No property findOne found for type Role!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1710) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:721) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
... 33 common frames omitted
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.lang.Object io.sunbits.lotteryapi.data.repository.ExtendedCrudRepository.findOne(java.io.Serializable)! No property findOne found for type Role!
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:82) ~[spring-data-jpa-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103) ~[spring-data-jpa-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:208) ~[spring-data-jpa-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:79) ~[spring-data-jpa-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:553) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:546) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_151]
at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_151]
at java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1049) ~[na:1.8.0_151]
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_151]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_151]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_151]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_151]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_151]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_151]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:548) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:538) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_151]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:538) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:317) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$3(RepositoryFactoryBeanSupport.java:287) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.util.Lazy.getNullable(Lazy.java:141) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.util.Lazy.get(Lazy.java:63) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:290) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:102) ~[spring-data-jpa-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
... 44 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findOne found for type Role!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:90) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:350) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:330) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:283) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324) ~[na:1.8.0_151]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:265) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:248) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:81) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:250) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_151]
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) ~[na:1.8.0_151]
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_151]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_151]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_151]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_151]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_151]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_151]
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:251) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:380) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_151]
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) ~[na:1.8.0_151]
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_151]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_151]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_151]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_151]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_151]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_151]
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:381) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:93) ~[spring-data-commons-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:76) ~[spring-data-jpa-2.0.5.RELEASE.jar:2.0.5.RELEASE]
... 70 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:40479', transport: 'socket'
Process finished with exit code 1
The problem is with your ExtendCrudRepository. You're trying to return a User for findOne(Long id), it should probably return type T since ExtendedCrudRepository is a generic interface.
When Spring Data tries to create the query for findOne() for the RoleRepository it's expecting to return a Role but you've harded coded a User as a return type.
#NoRepositoryBean
public interface ExtendedCrudRepository<T, ID extends Serializable> extends
JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
// You were returning a User here when it should return T
// Also it should take type ID
T findById(ID id);
// You were accepting a User here as a Id parameter when should
// be type ID since it is generic.
void deleteById(ID id);
}
CrudRepository Documentation
Update
Spring Data has changed naming scheme for CrudRepository
interface CrudRepository<T, ID> {
<S extends T> … save(S entity);
// Previously save(Iterable)
<S extends T> … saveAll(Iterable<S> entities);
// Previously findOne(ID)
… findById(ID id);
// Previously exists(…)
… existsById(ID id);
… findAll();
… findAllByIds(Iterable<ID> ids);
… count();
// Previously delete(ID)
… deleteById(ID id);
… delete(T entity);
// Previously delete(Iterable)
… deleteAll(Iterable<? extends T> entities);
… deleteAll();
}
https://jira.spring.io/browse/DATACMNS-944