Propagation of exceptions in Spring Boot - java

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

Related

ProGuard will make Spring Bean name conflict

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.

#PostContruct giving NullPointerException during server startup

I am getting Null Pointer Exception during server startup in the first line.
public class DefaultAreaPostalCodeService extends AbstractBusinessService implements AreaPostalCodeService {
private Map<String,List<PostalCodeData>> suburbMap;
#PostConstruct
#Transactional
public void initialize() {
List<AreaPostalCodeModel> postalCodes = areaPostalCodeDao.getAllAreaPostalCodes();
populateSuburbMap(postalCodes);
}
}
<bean id="areaPostalCodeService"
class="za.co.testro.core.address.impl.DefaultAreaPostalCodeService" parent="abstractBusinessService">
<property name="areaPostalCodeDao" ref="areaPostalCodeDao" />
</bean>
I simply want to populate the suburbMap at server startup so that I can use it later.
Error logs-
Error creating bean with name 'areaPostalCodeService': Invocation of
init method failed; nested exception is java.lang.NullPointerException
WARN [localhost-startStop-1] [CloseAwareApplicationContext] Exception
encountered during context initialization - cancelling refresh
attempt: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'areaPostalCodeService': Invocation of
init method failed; nested exception is java.lang.NullPointerException
Pinging the JVM took 10 seconds to respond. ERROR
[localhost-startStop-1] [HybrisContextFactory] Error initializing
global application context!
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'areaPostalCodeService': Invocation of init
method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
~[spring-beans-4.3.3.REL
EDIT 1:
I am still getting Null Pointer Exception after adding my code to afterProperties().
INFO [localhost-startStop-1] [ListMergeDirectiveBeanPostProcessor]
Post Processing ListMergeDirective
[promotionActionResultRaoExtractorListMergeDirective] on Bean
[cartRAOProviderExtractors] WARN [localhost-startStop-1]
[CloseAwareApplicationContext] Exception
encoujava.lang.NullPointerException WARN [localhost-startStop-1]
[CloseAwareApplicationContext] Exception encountered during context
initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'areaPostalCodeService' defined in class path
resource [testcore-spring.xml]: Invocation of init method failed;
nested exception is java.lang.NullPointerException ERROR
[localhost-startStop-1] [HybrisContextFactory] Error initializing
global application context!
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'areaPostalCodeService' defined in class path
resource [testcore-spring.xml]: Invocation of init method failed; ne
sted exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]ntered during context
initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'areaPostalCodeService' defined in class path
resource [testcore-spring.xml]: Invocation of init method failed;
nested exception is
EDIT 2:
Still getting Null Pointer Exception after calling the bean with application context.
Registry.getApplicationContext().getBean("areaPostalCodeDao", AreaPostalCodeDao.class).getAllAreaPostalCodes()
Error logs-
INFO [localhost-startStop-1] [ListMergeDirectiveBeanPostProcessor]
Post Processing ListMergeDirective
[promotionActionResultRaoExtractorListMergeDirective] on Bean
[cartRAOProviderExtractors] WARN [localhost-startStop-1]
[CloseAwareApplicationContext] Exception encountered during context
initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'areaPostalCodeService' defined in class path
resource [testcore-spring.xml]: Invocation of init method failed;
nested exception is java.lang.NullPointerException WARN
[localhost-startStop-1] [CloseAwareApplicationContext] Exception
encountered during context initialization - cancelling refresh
attempt: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'areaPostalCodeService' defined in class
path resource [testcore-spring.xml]: Invocation of init method failed;
nested exception is java.lang.NullPointerException ERROR
[localhost-startStop-1] [HybrisContextFactory] Error initializing
global application context!
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'areaPostalCodeService' defined in class path
resource [testcore-spring.xml]: Invocation of init method failed; ne
sted exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
Caused by: org.springframework.beans.FatalBeanException: Context
hybris Global Context Factory couldn't be created correctly due to,
Error creating bean with name 'areaPostalCodeService' defined in class
path resource [testcore-spring.xml]: Invocation of init method failed;
nested exception is java.lang.NullPointerException
at de.hybris.platform.core.HybrisContextFactory.build(HybrisContextFactory.java:314)
it is very normal to have such behavior, because #PostConstruct method will be called before injecting areaPostalCodeDao bean into areaPostalCodeDao property wich is null (for that moment).
There are 4 ways to run some code on bean initializing, but each way succeed in a specific step.
Spring bean setup lifecycle:
standard constructor
#PostConstruct
#Override afterPropertiesSet() from InitializingBean interface
init-method
So in your case you should do as above :
import org.springframework.beans.factory.InitializingBean;
public class DefaultAreaPostalCodeService extends AbstractBusinessService implements AreaPostalCodeService,InitializingBean {
private Map<String,List<PostalCodeData>> suburbMap;
#Override
#Transactional
public void afterPropertiesSet() {
List<AreaPostalCodeModel> postalCodes = areaPostalCodeDao.getAllAreaPostalCodes();
populateSuburbMap(postalCodes);
}
}
A possible solution, maybe not specifically for this case but could help others, is to call the code from the view, call it on first glance. The code would be something like:
In XHTML
<f:metadata>
<f:viewAction action="#{myUI.myVoid()}"/>
</f:metadata>

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

Error creating bean with name - Grails 2.3.8

Grails 2.3.8 error searchable plugin 6.9 - Error creating bean with name grails.plugin.searchable.SearchableController
Error 2016-07-26 09:53:18,826 [localhost-startStop-1] ERROR
context.GrailsContextLoader - Error initializing the application:
Error creating bean with name
'grails.plugin.searchable.SearchableController': Initialization of
bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'searchableService': Initialization of bean
failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'compass': FactoryBean threw exception on
object creation; nested exception is
org.compass.core.mapping.MappingException: No converter defined for
type [org.bson.types.ObjectId]
The error occurs at runtime and I can't fixed it
My guess is that you have a searchable property of type org.bson.types.ObjectId. This is not a type that the searchable plugin natively knows how to index, so you have to define a converter for it.

Categories