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.
Related
Sometimes I get a BeanCreationException when starting a Java Spring Boot single-JAR application built by Gradle. My investigations show that it depends on the JAR file and how it has been built by Gradle. Most often (but not always) I see the exception when I build the project on a Linux system. But I have never reproduced the issue with a JAR built on Windows or when running from IntelliJ Idea.
I tried to compare the content of a working JAR with the JAR throwing the exception - all the *.class files (including meta and resources) were binary equal, the only difference was in the order the files were stored in the JAR/ZIP archive. I also tried to unpack the failing JAR on Windows and just repack it into a new JAR file (using 7-zip) - the application started without any exceptions. This weird workaround solved the issue, but it's not something I'd like to do after each build on a linux machine.
The exception suggests to check circular references, so I tried replacing #Autowired properties with #Autowired bean constructors to help me to find the problem but that didn't help. The stacktrace does not mention any of my classes, so I don't know what bean could be responsible for the issue. And because of the fact the issue happens only sometimes and is solvable by repacking the JAR file, I'm not sure there are any circular references anyway.
Could you please help me? Any advice or suggestion is welcomed.
JDK: openjdk 8u262
Gradle version 5.6
Spring boot 2.3.1
Exception message:
BeanCreationException: Error creating bean with name 'webConfig':
Invocation of init method failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]:
Unsatisfied dependency expressed through method 'requestMappingHandlerAdapter' parameter 0;
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'mvcContentNegotiationManager':
Requested bean is currently in creation: Is there an unresolvable circular reference?
By default, Spring manages itself bean's lifecycle and then, arranges their initialization order during the startup.
Here a full example of usage #DependsOn annotation to order the bean instanciation.
You can also found more detail in the official Spring documentation
When I run spring boot I get the following error. I have replaced sensitive parts with '...' as the problem should be clear anyway. This error happened without me changing any of the code in the class that is causing the error.
Description:
The bean '...', defined in class path resource [....class], could not
be registered. A bean with that name has already been defined in URL
[jar:file:/C:/m2/repository/.../0-SNAPSHOT/...-0-SNAPSHOT.jar!/...class]
and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting
spring.main.allow-bean-definition-overriding=true
I have a springboot application. When I add spring-boot-starter-actuator dependency to my pom it gives UnsatisfiedDependencyException.
Without this dependency, application is running. When I put it, application not running.
Can anyone provide a solution for this?
Error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'servoMetricCollector' defined in class path resource
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
I develop a Roo project and deploy to a Tomcat 6 server.
Up until now everything was working fine.
I deleted and re-added an entity.
Now everytime when I start Tomcat I get this exception in the Spring Tool Suite:
SEVERE: StandardWrapper.Throwable
Throwable occurred: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#0': Cannot create inner bean '(inner bean)' of type [org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'applicationConversionService' while setting constructor argument; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [myproject.web.ApplicationConversionServiceFactoryBean] for bean with name 'applicationConversionService' defined in ServletContext resource [/WEB-INF/spring/webmvc-config.xml]; nested exception is java.lang.ClassNotFoundException: myproject.web.ApplicationConversionServiceFactoryBean
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [myproject.web.ApplicationConversionServiceFactoryBean] for bean with name 'applicationConversionService' defined in ServletContext resource [/WEB-INF/spring/webmvc-config.xml]; nested exception is java.lang.ClassNotFoundException: myproject.web.ApplicationConversionServiceFactoryBean
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
...
What do I need to do to make it work again?
spring is complainig about a bean not being available (probably the one you say you deleted).
exception is java.lang.ClassNotFoundException: myproject.web.ApplicationConversionServiceFactoryBean
try to search the config xml files & remove the reference made to this class, things should be back after that,
I had the same exact issue.
The problem was that I disabled the "Project > Build Automatically" feature, so I had to manually build the project.
Once I manually built the project everything went back to normal. :)
So, don't forget to build the project before deploying it, or just re-enable the "Project > Build Automatically" feature.
Hope it helps.
Your app deployed to Tomcat doesn't have a jar file in WEB-INF/lib that contains the class myproject.web.ApplicationConversionServiceFactoryBean. I don't know what that class is or where you'd find it, but it's missing.
my workaround (worked with eclipse and roo 1.1.5 as eclipse plugin)
open ApplicationConversionServiceFactoryBean.java class
delete class annotation #RooConversionService
wait for roo update
add back class annotation #RooConversionService
wait for roo update and try again
Inside of STS, click ->project->clean
It clean and discard all build problems and built states, The next time a build occurs the projects will be rebuilt from scratch.