ProGuard will make Spring Bean name conflict - java

Startup error
2020-11-06 18:07:31.452 WARN 13120 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.maple.MapleApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'a' for bean class [com.maple.a.d.a.a] conflicts with existing, non-compatible bean definition of same name and class [com.maple.a.b.a]
2020-11-06 18:07:31.463 ERROR 13120 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.maple.MapleApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'a' for bean class [com.maple.a.d.a.a] conflicts with existing, non-compatible bean definition of same name and class [com.maple.a.b.a]
I tried to use Spring definition.getBeanClassName() naming rules, but it didn’t work. Is it too much trouble if you want to manually set the name of each bean on the annotation? Can ProGuard provide the function of not repeating the class name? I haven’t found it yet.

Related

class path resource [WEB-INF/web.xml] cannot be opened because it does not exist

Maybe someone faced such a problem. The web.xml file is on the WEB-INF/web.xml path, but the error says otherwise.
2022-11-16 17:40:56.120 WARN 3272 --- [main] s.c.a.AnnotationConfigApplicationContext :
Exception encountered during context initialization - cancelling refresh
attempt: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'securityConfiguration': Unsatisfied
dependency expressed through field 'webXmlRolesParser'; nested exception
is org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'webXmlRolesParser' defined in class path resource
[by/belinvest/panel/admin/config/SecurityConfiguration.class]: Invocation
of init method failed; nested exception is java.io.FileNotFoundException:
class path resource [WEB-INF/web.xml] cannot be opened because it does not exist

HstSiteConfigurer: ComponentManager initialization failed

I'm working on One Hippo CMS, when I run the Tomcat server I'm getting this error
5.02.2019 18:23:45 ERROR main [DefaultHstSiteConfigurer.initializeComponentManager:264] HstSiteConfigurer: ComponentManager initialization failed.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.hippoecm.hst.content.beans.manager.ObjectConverter' defined in class path resource [org/hippoecm/hst/site/container/SpringComponentManager-content-beans.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Annotated class 'org.example.myproject.beans.Urldemo' for primarytype 'myproject:urldemo' is a duplicate of already registered class 'org.example.myproject.beans.Simple'. You might have configured a bean that does not have a annotation for the jcrType and inherits the jcrType from the bean it extends, resulting in 2 beans with the same jcrType. Correct your beans.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745) ~[spring-beans-5.1.1.RELEASE.jar:5.1.1.RELEASE]
Check the annotations on:
org.example.myproject.beans.Urldemo
org.example.myproject.beans.Simple
They should each have an annotation similar to:
#Node(jcrType = "project:doctype")
Each needs a unique jcrType value.

Propagation of exceptions in Spring Boot

does Spring Boot wraps/hides/encapsulates exceptions one way or another ?
I get some strange behaviour when an exception is produced.
For instance, in a Spring Boot + JPA project, if i comment out the #Entity annotation :
#Table(name = "XXX")
//#Entity
public class Contract
{
...
}
i get the following exception (warning) :
2018-12-10 19:09:33.153 DEBUG DESKTOP-48HHHCD --- [ost-startStop-1] o.h.c.CollectionSecondPass : Second pass for collection: cp.dmo.bean.ContribuablePar.listeContratMensu
2018-12-10 19:09:33.153 DEBUG DESKTOP-48HHHCD --- [ost-startStop-1] o.h.c.a.CollectionBinder : Binding a collection of element: cp.dmo.bean.ContribuablePar.listeContratMensu
2018-12-10 19:09:33.154 WARN DESKTOP-48HHHCD --- [ost-startStop-1] o.s.b.f.s.DefaultListableBeanFactory : Bean creation exception on non-lazy FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testpopulationserviceso' defined in file [C:\Users\celfer\AppData\Local\Temp\1-dmo\WEB-INF\classes\conf\application\applicationContext-service.xml]: Cannot resolve reference to bean 'testpopulationserviceimpl' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testpopulationserviceimpl' defined in file [C:\Users\celfer\AppData\Local\Temp\1-dmo\WEB-INF\classes\conf\application\applicationContext-service.xml]: Cannot resolve reference to bean 'testpopulationdao' while setting bean property 'testpopulationdao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testpopulationdao' defined in file [C:\Users\celfer\AppData\Local\Temp\1-dmo\WEB-INF\classes\conf\application\applicationContext-dao.xml]: Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in URL [jar:file:/C:/Users/celfer/AppData/Local/Temp/1-dmo/WEB-INF/lib/lombok-jpa-24.0.6-SNAPSHOT.jar!/conf/applicationContext-datasources-jpa2.xml]: Cannot resolve reference to bean 'entityManager' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManager' defined in URL [jar:file:/C:/Users/celfer/AppData/Local/Temp/1-dmo/WEB-INF/lib/lombok-jpa-24.0.6-SNAPSHOT.jar!/conf/applicationContext-datasources-jpa2.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
2018-12-10 19:09:33.155 DEBUG DESKTOP-48HHHCD --- [ost- startStop-1] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'lecturepersonneso'
So the exception says the application is unable to build a Hibernate SessionFactory but it does not point out precisely where the problem comes from.
Any clue ?
Thanks

HikariPool-1 - jdbcUrl is required with driverClassName

I went back to programming my old program https://github.com/JonkiPro/REST-Web-Services. I've updated Spring Boot from version 15.6 to version 2.0.0. I have encountered many problems with compilation, but I can not deal with one. Well, during compilation, he throws me in the console
2018-03-18 21:54:53.339 ERROR 3220 --- [ost-startStop-1] com.zaxxer.hikari.HikariConfig : HikariPool-1 - jdbcUrl is required with driverClassName.
2018-03-18 21:54:55.392 INFO 3220 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'unit'
2018-03-18 21:54:56.698 INFO 3220 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'unit'
2018-03-18 21:54:56.778 ERROR 3220 --- [ost-startStop-1] com.zaxxer.hikari.HikariConfig : HikariPool-1 - jdbcUrl is required with driverClassName.
2018-03-18 21:54:56.782 ERROR 3220 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService' defined in file [C:\Users\Jonatan\Documents\GitHub\REST-Web-Services\web\out\production\classes\com\web\web\security\service\impl\UserDetailsServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#65d6e77b' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#65d6e77b': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.
2018-03-18 21:54:56.821 WARN 3220 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
I've never had such a mistake. I do not know what it means completely. My properties for the base look like this
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql:database
username: root
password: root
schema: classpath:/db/init/schema.sql
I do not know how to deal with this error. I've been programming quite a long time, but for the first time I'm meeting the concept of hikari. I'm using a Tomcat(in Spring Boot) server and a PostgreSQL database.
I had the same issue in another context.
From the 79. Data Access - Configure a Custom DataSource
if you happen to have Hikari on the classpath, this basic setup does not work, because Hikari has no url property (but does have a jdbcUrl property)
Hikari is the default pool in spring boot 2.
so you can replace the config
url: jdbc:postgresql:database -> jdbc-url: jdbc:postgresql:database
or you can keep the config but you need to define another Bean to handle the mapping (aliases)
#Bean
#Primary
#ConfigurationProperties("app.datasource")
public DataSourceProperties dataSourceProperties() {
return new DataSourceProperties();
}
#Bean
#ConfigurationProperties("app.datasource")
public DataSource dataSource(DataSourceProperties properties) {
return properties.initializeDataSourceBuilder().
.build();
}
Either remove spring.datasource.driver-class-name property or rename the spring.datasource.url property to spring.datasource.jdbc-url.
This is reported in your error:
java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName
First option looks cleaner and Spring Boot will figure out the default driver class name based on the spring.datasource.url property value (see org.springframework.boot.jdbc.DatabaseDriver class if you want to debug this).

Multiple liquibase configurations in spring boot

I have spring boot application which use 2 databases. I defined 2 configurations providing specified datasources. I want to have that datasources managed separately by liquibase. I defined 2 separated changelog files.
The problem is that I can't define 2 separate beans for liquibase.
Here are my config classes:
...
public class CCSConfiguration {
...
#Bean
#ConfigurationProperties("ccs.liquibase")
public LiquibaseProperties ccsLiquibaseProperties() {
return new LiquibaseProperties();
}
#Bean
public SpringLiquibase ccsLiquibase(LiquibaseProperties liquibaseProperties) {
...
}
...
}
...
public class CCAConfiguration {
...
#ConfigurationProperties("cca.liquibase")
public LiquibaseProperties ccaLiquibaseProperties() {
return new LiquibaseProperties();
}
#Bean
public SpringLiquibase ccaLiquibase(LiquibaseProperties liquibaseProperties) {
...
}
...
}
And properties:
cca:
liquibase:
change-log: classpath:config/liquibase/cca/master.xml
ccs:
liquibase:
change-log: classpath:config/liquibase/ccs/master.xml
With this config i get following error while running appliction:
2017-04-11 14:26:55.664 WARN 34292 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'liquibase' available
2017-04-11 14:26:55.711 WARN 34292 --- [ restartedMain] o.s.boot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.config.internalCacheAdvisor' defined in class path resource [org/springframework/cache/annotation/ProxyCachingConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor]: Factory method 'cacheAdvisor' threw exception; nested exception is java.lang.NullPointerException)
2017-04-11 14:26:55.939 ERROR 34292 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean named 'liquibase' that could not be found.
Action:
Consider defining a bean named 'liquibase' in your configuration.
So, is it possible to define multiple liquibase beans for different datasources?
there are two options:
you define a bean named liquibase to let spring-boot integrated process to update your schema on you first DS. You have to handle the second one by hand
you disable liquibase automatic update at startup with
enabled: false
and define your way DS and liquibase beans to update your two databases

Categories