I have autowired org.springframework.cloud.sleuth.Tracer in a service but getting the following error while building the project (mvn clean install). Although The applications runs through IDE and code works perfectly, but I need a way to remove the error while compiling the project.
Unsatisfied dependency expressed through constructor parameter 3;
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type 'org.springframework.cloud.sleuth.Tracer'
available: expected at least 1 bean which qualifies as autowire
candidate. Dependency annotations: {}
*************************** APPLICATION FAILED TO START ***************************
Description:
Parameter 3 of constructor in
com.mmt.corporate.payments.PaymentService required a bean of type
'org.springframework.cloud.sleuth.Tracer' that could not be found.
Action:
Consider defining a bean of type
'org.springframework.cloud.sleuth.Tracer' in your configuration.
have included org.springframework.cloud.sleuth this way in pom.xml :
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
The Sleuth's Tracer was present in version 1.3.x. Starting from version 2.x there's no more Tracer from Sleuth. There's one from Brave. Can you please upgrade to the latest version?
Related
After upgrading from springboot 2.3.9 to 2.6.6 I have a failing tests with the following error,
java.lang.AssertionError:
Expecting:
<Unstarted application context org.springframework.boot.test.context.assertj.AssertableApplicationContext[startupFailure=org.springframework.beans.factory.UnsatisfiedDependencyException]>
to have a single bean of type:
<com.air.dx.range.application.RangeApplicationService>:
but context failed to start:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'IRoRangeRepository': Unsatisfied dependency expressed through method 'setDialect' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.data.relational.core.dialect.Dialect' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
One observation after upgrading,
The class ConfigFileApplicationContextInitializer from spring-boot-test jar is modified to ConfigDataApplicationContextInitializer.
I have a spring boot application which runs well on my local, UAT, and Prod environments but when I deploy it in a staging environment, it gives the following error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'Bean 1': Unsatisfied dependency expressed through field 'Class 1'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'Bean2 of type Class1': Bean with the name 'Bean2' has been injected into other beans [Bean 3] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
I am not sure if it's related to the build process or what. I have checked the code, there are no circular dependencies. When I annotate Bean2 with #Lazy on Class3, it works well. But I am not able to figure out why it works on other environments and this annotation is needed only for the Staging.
I'm working on a multi-module Spring Boot project that can use non-spring plugins. Plugins are loaded using java.util.ServiceLoader. They may use spring beans provided by a ContextBridge implementing org.springframework.context.ApplicationContextAware. The end result looks like this:
app-folder/
plugins/
myplugin.jar
myapplication.jar
launcher-script.sh
The application and the plugins work as intended when started using the shell script:
java -Dloader.path=.,plugins -jar myapplication.jar "$#"
However, I can't figure out how to configure IntelliJ to start the application AND find the plugins so I would be able to debug more comfortably.
I've tried the following approaches
Adding the -Dloader.path config to the launch configuration doesn't seem to work. I have tried both Appliaction and Spring Boot launch configurations. This didn't seem to do anything. It just loads the main application but no plugins.
Adding the plugins through gradle:
compile fileTree(dir: 'dist/plugins', include: '**/*.jar')
This does load the plugin but fails to load the context which I take from the error message I get:
s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myServiceImpl': Unsatisfied dependency expressed through method 'setMyService' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.myapp.MyService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
So I added bean dependencies to the code in order to force a certain order in which beans get initialized:
Data-Access Module
interface Myservice {
...
}
#Service
#Qualifier("MyServiceBean")
class MyServiceImpl implements MyService {
...
}
ContextBridge inside Plugin
#Component
#DependsOn("MyService)
public class ContextBridgeImpl implements ContextBridge, ApplicationContextAware {
...
}
Then I get:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'MyService' available
What confuses me is the fact that everythings works when started from the console. Why not inside IntelliJ?
Edit
Screen shots showing launch configurations
This question already has answers here:
Autowiring :expected at least 1 bean which qualifies as autowire candidate for this dependency
(6 answers)
Closed 5 years ago.
I am having this error whenever I run my Spring MVC App. I have been trying to integrate Spring Security but have been unsuccessful at injecting my custom AuthenticationSuccessHandler and so I get the following error pertaining to the application context:
2017-11-07 16:05:03 ERROR ContextLoader:350 - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: \
Error creating bean with name 'webSecurityConfig': \
Unsatisfied dependency expressed through field 'auth'; \
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: \
No qualifying bean of type \
'org.springframework.security.web.authentication.AuthenticationSuccessHandler' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
I have my project on GitHub: https://github.com/riveraadrian571/Staging-Management-System-Modifed-.git . I am using an oracle database and in pom.xml file am using a jdbc driver that I have in my local repository so you may want to change that. I am also using tomcat server to run the app. Thanks in advance.
In WebSecurityConfig you have
#Autowired
AuthenticationSuccessHandler auth;
Which is an Interface. You need to specify any specific implementation from standard:
All Known Implementing Classes:
ForwardAuthenticationSuccessHandler,
SavedRequestAwareAuthenticationSuccessHandler,
SimpleUrlAuthenticationSuccessHandler
#see Spring Docs
Or implement your custom.
I have 2 projects.
One is a DAL project that does CRUD operations on a neo4j DB using spring neo4j APIs . This project is packaged as a jar and included in project #2.
Project #2 Is a Spring restful services project that uses spring boot to package and create an executable jar that runes on an embedded tomcat server.
When trying to run my executable jar that Spring boot has created for me I keep getting this exception.
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
Based off of my reading if I am using #ComponentScan I can give the annotation directories to look in. So I give it the base dir for my services project. And I give it the base dir for my included DAL.jar but still no luck here is what the annotation looks like.
Extracted from comments:
Component scan declaration
#ComponentScan({"com.foo.dal.*","com.foo.notification.*"})
Stacktrace:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pushCommandsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.teradata.dal.example.PushRepository com.teradata.notification.rest.controller.PushCommandsController.repository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.teradata.dal.example.PushRepository] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
UPDATE:
based off of #chrylis answer:
Made change to #ComponenetScan
#ComponentScan({"com.teradata.notification","com.teradata.dal"})
running in to:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration' is defined
MORE DETAIL ON THE DAL PROJECT AND THE SERVICE PROJECT:
DAL PROJECT:
Services Project:
The argument to #ComponentScan is a package name, and those strings aren't valid packages. Drop the .* from them; Spring scans subpackages automatically.
Had this same issue for a short while, then #EntityScan did the trick for me, just as adviced here - Spring Boot w/ JPA: move #Entity to different package.
Hope that helps