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

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>

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.

WSS with red5 not loading

I have minimal experience with java and tomcat.
I am trying to get wss going so I can get an application to connect to my current running service.
I am trying to get avchat working in SSL for the mobile plugin. The support they have is non-existent an have seen some things on google but need some help with my errors.
I have added this code to jee-container.xml
<bean id="webSocketTransport" class="org.red5.net.websocket.WebSocketTransport">
<property name="addresses">
<list>
<value>${ws.host}:${ws.port}</value>
</list>
</property>
</bean>
<bean id="webSocketTransportSecure" class="org.red5.net.websocket.WebSocketTransport">
<property name="secureConfig">
<bean id="webSocketSecureConfig" class="org.red5.net.websocket.SecureWebSocketConfiguration">
<property name="keystoreType" value="JKS"/>
<property name="keystoreFile" value="${rtmps.keystorefile}"/>
<property name="keystorePassword" value="${rtmps.keystorepass}"/>
<property name="truststoreFile" value="${rtmps.truststorefile}"/>
<property name="truststorePassword" value="${rtmps.truststorepass}"/>
</bean>
</property>
<property name="addresses">
<list>
<value>${wss.host}:${wss.port}</value>
</list>
</property>
</bean>
When I start red5 i get this error
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSocketSecureConfig' defined in class path resource [jee-container.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'keystoreType' of bean class [org.red5.net.websocket.SecureWebSocketConfiguration]: Bean property 'keystoreType' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1237)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:552)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299)
... 19 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'keystoreType' of bean class [org.red5.net.websocket.SecureWebSocketConfiguration]: Bean property 'keystoreType' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:243)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:423)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1525)
... 23 more
Bootstrap exit
Debug shows
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSocketTransportSecure' defined in cl ass path resource [jee-container.xml]: Cannot create inner bean 'webSocketSecureConfig' of type [org.red5.net.websocket.SecureWebSocketCon figuration] while setting bean property 'secureConfig'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSocketSecureConfig' defined in class path resource [jee-container.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'keystoreType' of bean class [org.red5.net.websocke t.SecureWebSocketConfiguration]: Bean property 'keystoreType' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Couldn't create Solr Repository using Spring Data Solr

I couldn't create Spring Solr Repository.
Below is my bean configuration
<context:annotation-config />
<solr:solr-server id="solrServer" url="http://soms-env.staples.com:8983/solr" />
<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate"
scope="singleton">
<constructor-arg ref="solrServer" />
</bean>
<bean id="searchRepository"
class="com.solr.repository.SolrCurrencyRepository">
<property name="solrOperations" ref="solrTemplate" />
</bean>
and the code used in my controller is
#Autowired
private SolrCurrencyRepository searchRepository;
Getting below error all the time.
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.solr.repository.SolrCurrencyRepository Controller.MainController.searchRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.solr.repository.SolrCurrencyRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
Am I missing anything to instantiate Repository.

Error creating bean with name 'mongoTemplate'

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.

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