Null pointer exception while initializing listener - spring

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PurchaseAccount': Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: java.lang.NullPointerException
can u tell me y this exception is caused?

... How about you provide some more information. There is not way for anyone to know what is wrong with your code when you don't give any. Please also let us know what have you done already to try to solve your problem.

Related

org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#114a85c2 has been closed already

I found below exception after loading springboot.
[2020-01-06 20:03:39.173][main (1)][WARN ][o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.task.scheduling-org.springframework.boot.autoconfigure.task.TaskSchedulingProperties': Could not bind properties to 'TaskSchedulingProperties' : prefix=spring.task.scheduling, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#114a85c2 has been closed already
I don’t understand this error.
Please let me know why this exception is generated.

org.apache.ibatis.type.TypeException: The alias 'Criterion' is already mapped to the value 'com.xxx.domain.def.GameListExample$Criterion'

I use mybatis generator to generate domain and mapper. It works well when I generate one table.
When I generate another table , the problem comes. It seems like the Criterion class in GameListExample and BetRecdExample conflicts, but it was generated by mybatis.
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'betRecdMapper' defined in file
[F:\IdeaProjects\game\target\classes\com\good\game\dao\def\BetRecdMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource
[org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]:
Factory method 'sqlSessionFactory' threw exception; nested exception is org.apache.ibatis.type.TypeException: The alias 'Criterion' is already mapped to the value 'com.good.game.domain.def.GameListExample$Criterion'.
Sounds like the same issue as https://github.com/mybatis/generator/issues/461
It's caused by a bug in mybatis-spring 2.0.1.
https://github.com/mybatis/spring/issues/362
Current workaround is to use mybatis-spring 2.0.0 or 2.0.2-SNAPSHOT.

Spring singleton created, destroyed, created again

I am seeing a peculiar behavior in Spring 3.2.5
One of my beans is created as a consequence of AbstractBeanFactory#getType
Then Spring throws an exception along the lines of
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'A' defined in class path resource [config.xml]: Cannot resolve reference to bean 'B' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'B': Requested bean is currently in creation: Is there an unresolvable circular reference?
As the result of that exception, my bean is destroyed.
Later, my bean is created again, from a different getType() call. Tghis time Spring does not have any circular path problems.
Eventually, the entire context is created successfully, with the second copy of my bean retained as singleton.
My question is - is that behavior normal? Or am I doing something wrong? My bean has side effects in its init() method, so if this is a normal behavior of Spring, I'll need to add a destroy() method to it...
Edit:
To clarify the questions about the exception: The beans mentioned in exception are not exactly relevant because the context (including the beans A and B) is eventually created successfully, so there really is no circular dependency. However, for the completeness' sake, bean A takes bean B as constructor argument.

spring rabbitmq: can't set id as a property?

I have a property file which contains queue whose value is queue_name
If I use the property in other please, then it works, but if I used it on "id", then it failed
<rabbit:queue id="${queue}" name="queue" />
The error is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.amqp.rabbit.config.BindingFactoryBean#0': Cannot resolve reference to bean 'queue_name' while setting bean property 'destinationQueue'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ConnectorInputQueue_silo' is defined.
update:
I found the following log: it said bean ${queue} is created, so why didn't it replace ${queue} with the value of property of "queue"?
2014-11-21 05:27:11 DEBUG DefaultListableBeanFactory:220 - Creating shared instance of singleton bean '${queue}'
2014-11-21 05:27:11 DEBUG DefaultListableBeanFactory:450 - Creating instance of bean '${queue}'
2014-11-21 05:27:11 DEBUG DefaultListableBeanFactory:524 - Eagerly caching bean '${queue}' to allow for resolving potential circular references
2014-11-21 05:27:11 DEBUG DefaultListableBeanFactory:478 - Finished creating instance of bean '${queue}'
Show, please, more info to reproduce the issue. And pay attention that your StackTrace says:
No bean named 'ConnectorInputQueue_silo' is defined.
Maybe it will help you somehow...

Spring - Instanciate a bean with a class which throws an Exception

I'm trying to instanciate a bean which constructor could throw an Exception.
I can't modify this class (given by an external team).
<bean id="myClass" class="myClass" />
The myClass constructor throws Exception.
I've been thinking about extending this class with a Singleton Pattern which is the behavior I want (be sure to instantiate only one instance of MyClass).
Error message :
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'myClass'
defined in class path resource
[.../spring_applicationContext.xml]:
Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class
[myClass]:
Constructor threw exception; nested exception is
java.lang.ExceptionInInitializerError
Thanks in advance for your answers
I think the problem comes from the fact that my constructor throws an Exception.
My question is : with Spring, is it possible to instanciate a bean with a constructor which could throw an exception ?
If no bean scope is specified in bean configuration file, default to singleton. Your bean myClass is a singleton and you dont need to do anything more.
Spring Doc
Spring beans are by default singletons.
You should provide more of the stacktrace - what you're showing indicates that it is not myClass that is the problem, but the ClassPathXmlApplicationContext constructor that throws an exception - the cause usually follows later in the stacktrace.
Cheers,
As per stack trace, looks like there is an unexpected error either in static block or variable while creating an object of class 'myClass'.

Resources