Error creating bean with name 'mongoTemplate' - java

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate'
defined in class com.socketcruiter.config.SpringMongoConfig: Instantiation of bean failed;
nested exception is org.springframework.beans.factory.BeanDefinitionStoreException:
Factory method [public org.springframework.data.mongodb.core.MongoTemplate org.springframework.data.mongodb.config.AbstractMongoConfiguration.mongoTemplate()
throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'mappingMongoConverter' defined in class com.socketcruiter.config.SpringMongoConfig:
Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException:
Factory method [public org.springframework.data.mongodb.core.convert.MappingMongoConverter org.springframework.data.mongodb.config.AbstractMongoConfiguration.mappingMongoConverter()
throws java.lang.Exception] threw exception; nested exception is java.lang.NoSuchMethodError:
org.springframework.data.util.ClassTypeInformation.from(Ljava/lang/Class;)Lorg/springframework/data/util/ClassTypeInformation;
i have the following config
<mongo:mongo host="127.0.0.1" port="27017" />
<mongo:db-factory dbname="ssss" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
</bean>
and im using
org.springframework.data
spring-data-mongodb
1.7.1.RELEASE

Check if you have the correct jar in your class path.
You would need spring-data-commons-core jar, here is the latest version:
http://mvnrepository.com/artifact/org.springframework.data/spring-data-commons-core/1.4.1.RELEASE

If the user name and password of your monogodb are empty, comment it out in the configuration file and debug it again.

Related

Unable to initialize group definition. Group resource name - Session Factory in Hibernate

I am getting the below error while working with Hibernate. Could you please figure out what is causing this error.
org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition.
Group resource name [classpath*:beanRefFactory.xml], factory key [BeanFactory]; nested exception
is org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'BeanFactory' defined in URL [jar:file:/E:/Client/
post/test.jar!/beanRefFactory.xml]: Instantiation of bean failed; nested exception
is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class
[org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'SessionFactory' defined in class path resource [applicationContext.xml]: Invocation of
init method failed; nested exception is java.lang.VerifyError: class
net.sf.cglib.core.DebuggingClassWriter overrides final method
org.objectweb.asm.ClassWriter.visit(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;
[Ljava/lang/String;)V
at
org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:389)
....
....
....
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.VerifyError: class net.sf.cglib.core.DebuggingClassWriter overrides final method org.objectweb.asm.ClassWriter.visit(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:108)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
... 155 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.VerifyError: class net.sf.cglib.core.DebuggingClassWriter overrides final method org.objectweb.asm.ClassWriter.visit(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
I have defined the session factory bean as below in the applicationcontext.xml file and getting the database connection values from separate file database.properties.
<bean id="SessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="JobDataSource" />
<property name="mappingResources">
<list>
<value>Entry.hbm.xml</value>
<value>AccountMapping.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
</props>
</property>
</bean>
please help me to solve this error and cause of this error too. any help is appreciated, Thanks
The version of ASM that is expected by cglib is not the same as used at runtime. Looks like you might have messed up your dependencies or use incompatible versions.

How do you inject com.github.benmanes.caffeine.cache.Cache via Spring?

This is how my cache is instantiated:
return Caffeine.newBuilder()
.maximumSize(10)
.expireAfterWrite(15, TimeUnit.MINUTES)
.build()
How can I configure Spring to perform dependency injection?
<bean id="matchedDFUCache" class="com.github.benmanes.caffeine.cache.Caffeine" factory-method="newBuilder"></bean>
is giving me this error:
[coral:launch] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'realTimeForecastFactory': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'matchedDFUCache' is expected to be of type 'com.github.benmanes.caffeine.cache.Cache' but was actually of type 'com.github.benmanes.caffeine.cache.Caffeine'
This is the source file: https://github.com/ben-manes/caffeine/blob/master/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java
<bean id="caffeineBuilder" class="com.github.benmanes.caffeine.cache.Caffeine" factory-method="newBuilder">
</bean>
<bean id="matchedDFUCache" factory-bean="caffeineBuilder" factory-method="build">
</bean>

Not able to integrate liquibase with my spring boot project- getting error with many beans

I am trying to add liquibase to my current project. Even after following all the necessary steps, I am getting the following error
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'profileController' defined in URL [jar:file:/C:/Users/if994410/.m2/repository/org/springframework/data/spring-data-rest-webmvc/3.3.0.RELEASE/spring-data-rest-webmvc-
3.3.0.RELEASE.jar!/org/springframework/data/rest/webmvc/ProfileController.class]: Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'repositoryRestConfiguration' defined in class path resource
[org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.data.rest.core.config.RepositoryRestConfiguration]: Factory method 'repositoryRestConfiguration' threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositories' defined in class path resource
[org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.repository.support.Repositories]: Factory method 'repositories' threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configDataRepository' defined in
net.ssnc.springboot.repository.ConfigDataRepository defined in #EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property
'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested
exception is java.lang.IllegalStateException: Failed to asynchronously initialize native EntityManagerFactory: java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: Provider
com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule not found
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
….. etc.....
This is my changelog master
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<include file="changelog-v1.0.xml"/>
</databaseChangeLog>
This is my changelog
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet id="changelog-v1.0.0" author="xyz">
<addColumn tableName = "schematrack">
<column name = "id" type = "UUID" />
<column name = "s" type = "jsonb" />
<column name = "type" type = "character varying(255)" />
<column name = "version" type = "character varying(255)" />
</addColumn>
</changeSet>
</databaseChangeLog>
Apart from the database integration stuff, this is added in the application.properties
spring.flyway.enabled=false
spring.liquibase.enabled=true
spring.application.name=test
spring.liquibase.change-log=classpath:changelog-master.xml
What changes should I make so that I can get rid of the error?
P.S.: The necessary tables (3 of them) were successfully created!

Can't store BLOB using Oracle + Spring + Liberty profile

I receive ClassNotFoundException : oracle.sql.BLOB exception storing blob in DB. Here is my conf:
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor" />
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler">
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor" />
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="DataBase" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>
I changed it like this:
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor"/>
and now I receive:
[ERROR ] Context initialization failed
Error creating bean with name 'clusterizer': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private ru.sbrf.indexer.dao.ClusterizerDao ru.sbrf.indexer.ClusterizerProcessor.clusterizerDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clusterizerDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.support.lob.LobHandler ru.sbrf.indexer.dao.ClusterizerDao.lobHandler; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandler' defined in ServletContext resource [/WEB-INF/spring/ds.xml]: Cannot resolve reference to bean 'nativeJdbcExtractor' while setting bean property 'nativeJdbcExtractor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nativeJdbcExtractor' defined in ServletContext resource [/WEB-INF/spring/ds.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Could not initialize WebSphereNativeJdbcExtractor because WebSphere API classes are not available: java.lang.ClassNotFoundException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection
[ERROR ] SRVE0283E: При инициализации контекста возникла исключительная ситуация: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clusterizer': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private ru.sbrf.indexer.dao.ClusterizerDao ru.sbrf.indexer.ClusterizerProcessor.clusterizerDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clusterizerDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.support.lob.LobHandler ru.sbrf.indexer.dao.ClusterizerDao.lobHandler; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandler' defined in ServletContext resource [/WEB-INF/spring/ds.xml]: Cannot resolve reference to bean 'nativeJdbcExtractor' while setting bean property 'nativeJdbcExtractor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nativeJdbcExtractor' defined in ServletContext resource [/WEB-INF/spring/ds.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Could not initialize WebSphereNativeJdbcExtractor because WebSphere API classes are not available: java.lang.ClassNotFoundException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2223)
at [internal classes]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Could not initialize WebSphereNativeJdbcExtractor because WebSphere API classes are not available: java.lang.ClassNotFoundException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1094)
... 51 more
Caused by: java.lang.IllegalStateException: Could not initialize WebSphereNativeJdbcExtractor because WebSphere API classes are not available: java.lang. ClassNotFoundException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection
at org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor.<init>(WebSphereNativeJdbcExtractor.java:65)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 53 more
but I can't find this com.ibm.ws.rsadapter.jdbc.WSJdbcConnection in LP and I don't want copy all dependencies from WAS. How do I store data in Liberty profile?

TokenServicesUserApprovalHandler not found in latest spring-security-oauth2-2.0.6.RELEASE.jar

<bean id="userApprovalHandler" class="org.springframework.security.oauth2.provider.approval.TokenServicesUserApprovalHandler">
<property name="tokenServices" ref="tokenServices" />
</bean>
The following code in my spring-security.xml was working with spring-security-oauth2-1.0.1.RELEASE.jar but when I upgraded it to spring-security-oauth2-2.0.6.RELEASE.jar the above file ie, "org.springframework.security.oauth2.provider.approval.TokenServicesUserApprovalHandler" was not found.
I was doing this because with previous jar there was some conflict regarding jackson due to Spring 4.1.X
17:14:53,679 WARN [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-1) Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.oauth2.provider.token.DefaultTokenServices
com.aricent.ans.controller.um.UserController.tokenServices; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenServices' defined in ServletContext resource [/WEB-INF/spring-security.xml]: Cannot
resolve reference to bean 'clientDetails' while setting bean property 'clientDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientDetails' defined in ServletContext resource
[/WEB-INF/spring-security.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.oauth2.provider.JdbcClientDetailsService]: Constructor
threw exception; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper
It was a change with the version of Spring OAuth2 you're using. Try this:
<bean id="userApprovalHandler" class="org.springframework.security.oauth2.provider.approval.TokenStoreUserApprovalHandler">
<property name="tokenStore" ref="tokenStore"/>
</bean>

Categories