I am attempting to convert an existing spring weblogic application to a spring boot embedded tomcat application.
There are lots of moving parts so it's hard to show any code, I'm hoping there is some general answer that might clue me in to the issue.
Under weblogic, using the spring-framework 4.3.6.RELEASE libraries, the application deploys fine. It has no problems creating the different service, repository and component beans.
However, when I migrate it to Spring Boot 1.5.1.RELEASE, I get the following error:
2017-06-21 17:08:16,402 [ERROR] SpringApplication reportFailure (815) - Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alertEventServiceImpl': Unsatisfied dependency expressed through field 'alertEventDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alertEventDaoImpl' defined in URL [jar:file:/Users/username/Development/source/carma-war/target/carma-war-2.0.0-SNAPSHOT.war!/WEB-INF/lib/protocol-manager-1.8.0-SNAPSHOT.jar!/org/ihc/hwcir/protocol/dao/AlertEventDaoImpl.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.ihc.hwcir.protocol.dao.AlertEventDaoImpl]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class org.ihc.hwcir.protocol.dao.AlertEventDaoImpl
Many of our service classes are final as they shouldn't be extended. Since there are so many that are final, I wanted to minimize the amount of code in our different libraries that we modify to make this work.
I thought because the bean creation process works under weblogic, it should work under spring boot.
Things I have tried to force not using the cglib proxies:
All implementations implement interfaces already
In beans created via xml, added <aop:scoped-proxy proxy-target-class="false"/>
In beans created through annotations, added (example for service bean)
#Service
#Scope(proxyMode = ScopedProxyMode.INTERFACE)
However, in the end, I'm perplexed as to why spring can create beans (the classes marked as final) under the weblogic container but unable to do so under the embedded tomcat spring-boot container.
Spring Boot by default uses class based proxies, which will not work with final classes/methods.
To disable this add spring.aop.proxy-target-class=false to the application.properties to enable JDK Dynamic Proxies instead of class based proxies. (And revert your modifications).
NOTE: To have everything take into account the spring.aop.proxy-target-class you might need to upgrade to Spring Boot 1.5.3 as some final patches where made to include this property in parts that were missed in previous versions.
See the following issues for more information 8434, 8869 and 8887.
I was unable to make this work using M. Deinums' answer using spring.aop.proxy-target-class=false.
What worked for me was to add in the application.properties file
spring.dao.exceptiontranslation.enabled=false
Please note that this option disables proxy creation for repositories.
And in my spring boot application configurer the annotation to handle transactions without using a proxy class.
#EnableTransactionManagement(proxyTargetClass = false)
This is using Spring Boot version 1.5.1.RELEASE.
Related
I have application with spring-boot-starter-actuator dependency. When I add my error handling library as dependency, application fails to start with the following message
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
After a bit research, I found out the error handling library introduces transitive dependency of spring-boot-starter-data-jpa which in turn causes actuator autoconfiguration to automatically introduce DataSourceHealthIndicator bean. This bean fails on missing database connection, but the application actually doesn't use database at all. However, the logging library requires the JPA dependency at runtime, so I can't exclude it.
I tried to set the following application property: management.health.db.enabled=false, but I still get the same error on startup. I can't find any documentation how to disable DataSourceHealthIndicator bean and leaving other autoconfiguration intact.
I have this spring boot project (version 2.3.3.RELEASE) that uses Spring Webflux and Spring Data and R2DBC. It was working fine until I added the following dependency:
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
After this, Spring can't start because it can't resolve the dependency for this object:
interface BookingCountRepository : ReactiveCrudRepository<BookingCount, String> {
...
}
The error message is the following:
2021-12-22 10:20:59,916 [main] ERROR [] o.s.b.d.LoggingFailureAnalysisReporter - __***************************_APPLICATION FAILED TO START_***************************__Description:__Parameter 1 of constructor in xx.xx.xx.xx.BookingService required a bean of type 'xx.xx.xx.xx.BookingCountRepository' that could not be found.___Action:__Consider defining a bean of type 'xx.xx.xx.xx.BookingCountRepository' in your configuration._
If I remove the spring-boot-starter-data-redis dependency, the problem stops happening.
My hunch is that it's probably a dependency hell issue, with a conflict between org.springframework.boot:spring-boot-starter-data-r2dbc and org.springframework.boot:spring-boot-starter-data-redis. But I don't know for sure.
Did anyone have trouble with this? If you did, how did you solve this problem?
FYI: JVM Runtime is OpenJDK 11, language is Kotlin, and spring boot version is 2.3.3.RELEASE
I was able to find a solution, therefore I'm posting here, since others may face the same problem.
The cause of the problem is that multiple spring data modules (r2dbc and redis) were being used in the same project. Since ReactiveCrudRepository is a generic interface that can be assigned to both Redis and R2DBC, something must be done to ensure Spring DI loads the correct spring data modules.
The solution, in this case, is making BookingCountRepository inherit directly from R2dbcRepository:
interface BookingCountRepository : R2dbcRepository<BookingCount, String> {
...
}
After that, everything will work correctly.
More information in the docs:
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.multiple-modules
Note: Some approaches, like informing basePackages in the #EnableR2dbcRepositories annotations didn't work.
I am new to the FiX protocol. I cam across this spring boot starter in which i am trying to familiarise myself with it https://github.com/esanchezros/quickfixj-spring-boot-starter.
I have created 2 spring boot apps. At the moment is literally comprises of the main method and the main class is annotated with #EnableQuickFixJClient and #EnableQuickFixJServer respectively.
Although the client/initiator starts up fine, the server/acceptor application does not. I get a bean error:
Consider defining a bean of type 'quickfix.Acceptor' in your configuration. I know what the error means but when defining the bean, there's several different constructor args i need to pass in and I'm not sure what to pass in.
These are my configurations:
quickfixj-server.cfg:
[default]
FileStorePath=target/data/acceptor
ConnectionType=acceptor
SenderCompID=EXEC
TargetCompID=BANZAI
StartTime=00:00:00
EndTime=00:00:00
HeartBtInt=5
ReconnectInterval=5
FileLogPath=logs-server
[session]
BeginString=FIX.4.1
SocketAcceptPort=9877
application.properties:
quickfixj.server.config=classpath:quickfixj-server.cfg
quickfixj.server.auto-startup=true
quickfixj.server.force-disconnect=false
quickfixj.server.phase=0
quickfixj.server.jmx-enabled=true
quickfixj.server.concurrent.enabled=true
quickfixj.server.message-store-factory=memory
quickfixj.server.log-factory=screen
Here you have a ready application with an example for the server and client (in one). You can modify it according to your needs and then develop it based on it.
https://github.com/esanchezros/quickfixj-spring-boot-starter-examples/tree/master/simple-client-and-server
I have stumbled upon one issue. I am using Spring for DI in my BDD tests. My components are Glue Scoped by marking components with #Scope("cucumber-glue"). But the issue now I am facing is this components are also needed to be used in my JUnit based tests. While trying to Autowire my components spring throws:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '<bean name>': Injection of autowired dependencies failed; nested exception is java.lang.IllegalStateException: No Scope registered for scope name 'cucumber-glue'
As per the suggestion in one of the older reported git hub issues I tried registering GlueCodeScope to glueCustomConfigurer Bean but that class is package restricted so I am unable to access it. Is there another way via which I can continue to use my components in BDD as well as JUnit tests. Note I have to use cucumber-glue scope in order to ensure my tests can run in parallel and that each scenario receives a fresh bean.
Using Spring Boot 1.5.12, we create scoped proxies for #ConfigurationProperties beans. We do this so that we can effectively have property values that are scoped to the user/session/etc. We use a BeanFactoryPostProcessor to register a scoped proxy created by ScopedProxyUtils.createScopedProxy and change the scope of the target bean definition to our custom scope.
This worked great in Spring Boot 1.5.12. However, in Spring Boot 2, the introduction of the Binder API has made this stop working. This is because when Spring Boot binds #ConfigurationProperties in its ConfigurationPropertiesBindingPostProcessor, it uses Bindable.of(type).withExistingValue(bean) passing in a type (e.g. org.example.Foo) and the bean which is an instance of ScopedProxyFactoryBean. Bindable checks that bean is an instance of type which it's not and things blow up.
Does anyone know of a general way to accomplish this? Specifically, to replace the #ConfigurationProperties bean definition with a proxy while still allowing the properties to bind to the instance? I've considered delaying the creation of the proxy until after the target has already been bound by ConfigurationPropertiesBindingPostProcessor (i.e. in my own BeanPostProcessor). However, at this point the bean is instantiated and my proxy can only replace the bean. It can't really leave the original bean in the context as a target. So I'm struggling with how to do this using a BeanPostProcessor.
EDIT: I've created a simple example project that demonstrates the issue (with the ability to check out code that works on Spring Boot 1 and fails on Spring Boot 2).