Spring 5.0.7 With Hibernate 5.4.1 on resin server - java

This example is working fine in Tomcat9 with same jar but not working in Resin 4.0.61 Web server
Configuration for Spring MVC in resin.xml file -
<servlet>
<servlet-name>springportfolio</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springportfolio-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup></servlet>
<servlet-mapping>
<servlet-name>springportfolio</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
springportfolio-servlet.xml configuration file-
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Add support for conversion, formatting and validation support -->
<mvc:annotation-driven />
<!-- Add support for component scanning -->
<context:component-scan
base-package="com.example.portfolio" />
<!-- Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix"
value="/web-inf/views/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- Step 1: Define Database DataSource / connection pool -->
<bean id="myDataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass"
value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl"
value="xxxxxx" />
<property name="user" value="xxxx" />
<property name="password" value="xxx" />
<!-- these are connection pool properties for C3P0 -->
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxIdleTime" value="30000" />
</bean>
<!-- Step 2: Setup Hibernate session factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan"
value="com.example.portfolio.entity" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle12cDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- Step 3: Setup Hibernate transaction manager -->
<bean id="myTransactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Step 4: Enable configuration of transactional behavior based on annotations -->
<tx:annotation-driven
transaction-manager="myTransactionManager" />
Getting Exception - ERROR | Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'customerController': Unsatisfied
dependency expressed through field 'userService'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'userServiceImp': Unsatisfied dependency
expressed through field 'userDao'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'customerDAOImpl': Unsatisfied
dependency expressed through field 'sessionFactory'; nested exception
is org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory' defined in ServletContext
resource [/WEB-INF/springportfolio-servlet.xml]: Invocation of init
method failed; nested exception is java.lang.NoSuchMethodError:
javax.persistence.Table.indexes()[Ljavax/persistence/Index;

Resin 4.0.61 conforms to JEE 6.0 specification. The JEE 6.0 includes JPA in version 2.0. According to the error message a JPA in version 2.1 is expected by the application. Either downgrade the application to JPA 2.0 or upgrade the server to JPA 2.1 as described in this forum

Related

Spring MVC error while creating sessionFactory for Hibernate Session Factory

I'm getting below error while creating the sessionFactory for hibernate in a spring MVC config file.
The error I am getting is:
encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-mvc-crud-demo-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net/bytebuddy/NamingStrategy$SuffixingRandom$BaseNameResolver
Nov 29, 2019 1:56:28 PM org.springframework.web.servlet.FrameworkServlet initServletBean
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-mvc-crud-demo-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net/bytebuddy/NamingStrategy$SuffixingRandom$BaseNameResolver
My Spring Config File is given below:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Add support for component scanning -->
<context:component-scan base-package="com" />
<!-- Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- Step 1: Define Database DataSource / connection pool -->
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.cj.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false&serverTimezone=UTC" />
<property name="user" value="root" />
<property name="password" value="DeepMYSQL9046!#" />
<!-- these are connection pool properties for C3P0 -->
<property name="initialPoolSize" value="5"/>
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxIdleTime" value="30000" />
</bean>
<!-- Step 2: Setup Hibernate session factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan" value="com" />
<property name="hibernateProperties">
<props>
<prop key="hibernate5.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate5.show_sql">true</prop>
</props>
</property>
</bean>
<!-- Step 3: Setup Hibernate transaction manager -->
<bean id="myTransactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Step 4: Enable configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="myTransactionManager" />
<!-- Add support for reading web resources: css, images, js, etc ... -->
<mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources>
</beans>

Java Spring MVC + Hibernate - sessionFactory "unsatisfied dependency" errror

I'm in the middle of creating my first Spring + Hibernate webapp and this is what I have in console:
Root Cause
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'quizDAOImpl': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.kubacki.entity.Quiz
I tried to find already existing solutions but nothing seems to work, would you be able to help me please?
I am not sure if the issue may be caused by bad XML configuration or some mistake in coding itself, from my perspective "sessionFactory" bean is correctly configured in XML and there should be no problem with injecting it.
Additionally, I'am using Maven for this project but I have already listed all spring + hibernate stuff in pom.xml
Here is my source code:
QuizDAO:
package com.kubacki.dao;
import java.util.List;
import com.kubacki.entity.Quiz;
public interface QuizDAO {
public Quiz getQuiz(int id);
public List<Quiz> getQuizzes();
}
QuizDAOImpl:
package com.kubacki.dao;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.kubacki.entity.Quiz;
#Repository
public class QuizDAOImpl implements QuizDAO {
#Autowired
private SessionFactory sessionFactory;
#Override
public Quiz getQuiz(int id) {
Session tempSession = sessionFactory.getCurrentSession();
Quiz tempQuiz = tempSession.get(Quiz.class, id);
return tempQuiz;
}
#Override
public List<Quiz> getQuizzes() {
Session tempSession = sessionFactory.getCurrentSession();
Query<Quiz> theQuery = tempSession.createQuery("from quiz", Quiz.class);
List<Quiz> tempQuizzes = theQuery.getResultList();
return tempQuizzes;
}
}
Web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>WebApp</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
dispatcher-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Add support for component scanning -->
<context:component-scan base-package="com.kubacki" />
<!-- Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- Step 1: Define Database DataSource / connection pool -->
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/quizdb?useSSL=false" />
<property name="user" value="root" />
<property name="password" value="admin" />
<!-- these are connection pool properties for C3P0 -->
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxIdleTime" value="30000" />
</bean>
<!-- Step 2: Setup Hibernate session factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan" value="com.kubacki.entity" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- Step 3: Setup Hibernate transaction manager -->
<bean id="myTransactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Step 4: Enable configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="myTransactionManager" />
</beans>
As per the error
No identifier specified for entity: com.kubacki.entity.Quiz
I think, You are missing a field annotated with #Id in Quiz class. Each #Entity must have an #Id - this will be a primary key in your database.

spring Injection of autowired dependencies failed

I have been running my project on Java 7 (exact version: jdk1.7.0_60) but since there is a company wide policy changed to upgrade to Java 8 (version: jdk1.8.0_73) I have upgraded my local machine's JVM to jdk1.8.0_73 and configured my project on this version.
Following are the facts for my project:
Spring Framework Version: 4.0.3.RELEASE
Java: jdk1.8.0_73
Since then my application is throwing following exceptions:
Feb 16, 2016 12:15:14 PM org.apache.catalina.core.StandardContext listenerStart
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 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#1': Cannot create inner bean 'com.asi.core.spring.interceptor.ThrottleRequestInterceptor#0' of type [com.asi.core.spring.interceptor.ThrottleRequestInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.asi.core.spring.interceptor.ThrottleRequestInterceptor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.asi.v1.ext.api.service.impl.ThrottleService com.asi.core.spring.interceptor.ThrottleRequestInterceptor.throttlerV1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'throttlerV1': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.web.client.RestTemplate com.asi.v1.ext.api.service.impl.ThrottleService.restTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restTemplate' defined in class path resource [spring/application-config.xml]: Cannot create inner bean 'org.springframework.http.converter.json.MappingJackson2HttpMessageConverter#4dd016c7' of type [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter] while setting bean property 'messageConverters' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.http.converter.json.MappingJackson2HttpMessageConverter#4dd016c7' defined in class path resource [spring/application-config.xml]: Cannot create inner bean 'org.springframework.http.MediaType#3ffc5996' of type [org.springframework.http.MediaType] while setting bean property 'supportedMediaTypes' with key [0]; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.ExpressionInvocationTargetException: A problem occurred when trying to execute method 'forName' on object of type [java.lang.Class]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
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 org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#1': Cannot create inner bean 'com.asi.core.spring.interceptor.ThrottleRequestInterceptor#0' of type [com.asi.core.spring.interceptor.ThrottleRequestInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.asi.core.spring.interceptor.ThrottleRequestInterceptor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.asi.v1.ext.api.service.impl.ThrottleService com.asi.core.spring.interceptor.ThrottleRequestInterceptor.throttlerV1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'throttlerV1': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.web.client.RestTemplate com.asi.v1.ext.api.service.impl.ThrottleService.restTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restTemplate' defined in class path resource [spring/application-config.xml]: Cannot create inner bean 'org.springframework.http.converter.json.MappingJackson2HttpMessageConverter#4dd016c7' of type [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter] while setting bean property 'messageConverters' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.http.converter.json.MappingJackson2HttpMessageConverter#4dd016c7' defined in class path resource [spring/application-config.xml]: Cannot create inner bean 'org.springframework.http.MediaType#3ffc5996' of type [org.springframework.http.MediaType] while setting bean property 'supportedMediaTypes' with key [0]; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.ExpressionInvocationTargetException: A problem occurred when trying to execute method 'forName' on object of type [java.lang.Class]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:290)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:632)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:470)
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1071)
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:277)
at org.springframework.web.servlet.handler.AbstractHandlerMapping.detectMappedInterceptors(AbstractHandlerMapping.java:221)
at org.springframework.web.servlet.handler.AbstractHandlerMapping.initApplicationContext(AbstractHandlerMapping.java:196)
at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:120)
at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:73)
at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:74)
at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:119)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:94)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
... 20 more
Here is my spring configurations:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:web-services="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven/>
<web-services:annotation-driven/>
<web-services:dynamic-wsdl id="productSearch" portTypeName="ProductSearch"
targetNamespace="http://www.asicentral.com/schema/product" locationUri="/productSearchService">
<web-services:xsd location="/WEB-INF/product.xsd"/>
</web-services:dynamic-wsdl>
<web-services:dynamic-wsdl id="loginAPI" portTypeName="LoginAPI"
targetNamespace="http://www.asicentral.com/schema/login" locationUri="/loginAPI">
<web-services:xsd location="/WEB-INF/login.xsd"/>
</web-services:dynamic-wsdl>
<web-services:dynamic-wsdl id="batchAPI" portTypeName="BatchAPI"
targetNamespace="http://www.asicentral.com/schema/batch" locationUri="/batchAPI">
<web-services:xsd location="/WEB-INF/batch.xsd"/>
</web-services:dynamic-wsdl>
<context:component-scan base-package="com.asi"></context:component-scan>
<mvc:interceptors>
<bean class="com.asi.core.spring.interceptor.ThrottleRequestInterceptor" />
</mvc:interceptors>
<cache:annotation-driven />
<import resource="v1.xml"/>
<!-- When more versions are listed load version specific xml config -->
<import resource="v2.xml"/>
<import resource="v3.xml"/>
<bean id="headerHandler" class="com.asi.v1.service.resource.util.ExternalApiHeaderHandler" />
<bean id="ExternalApiApplicationContextProvider" class="com.asi.core.spring.config.provider.ExternalApiApplicationContextProvider"></bean>
<bean id="environmentConfigurator" class="com.asi.ext.api.config.EnvironmentConfigurator">
<property name="env" value="${Ext.env}"></property>
<property name="lookupRestTemplate" ref="restTemplate"></property>
</bean>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:config-location="classpath:ehcache.xml"/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache"/>
<context:property-placeholder location="classpath:${Ext.env}-environment.properties, classpath:velocity-import*.properties, classpath:radar-version.properties" order="1"/>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml"/>
<entry key="html" value="text/html"/>
<entry key="json" value="application/json"/>
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</list>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
</list>
</property>
</bean>
<bean id="dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="jdbcUrl" value="jdbc:sqlserver://${db.velocity.host}:${db.velocity.port};databaseName=${db.velocity.database}" />
<property name="user" value="${db.velocity.username}" />
<property name="password" value="${db.velocity.password}" />
<!-- these are C3P0 properties -->
<property name="acquireIncrement" value="1" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxIdleTime" value="300" />
</bean>
<bean id="hibernate3AnnotatedSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.asi.ext.api.dao.ExternalAPILogger</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
</bean>
<bean id="logDAO" class="com.asi.ext.api.dao.ExternalApiLoggerImpl">
<property name="sessionFactory" ref="hibernate3AnnotatedSessionFactory" />
</bean>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg value="application" />
<constructor-arg value="json" />
<constructor-arg value="#{T(java.nio.charset.Charset).forName('UTF-8')}"/>
</bean>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter ">
<constructor-arg value="#{T(java.nio.charset.Charset).forName('UTF-8')}"/>
</bean>
</list>
</property>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>error</value>
</property>
</bean>
</beans>
whereas, the v1, v2 & v3.xml imports are for different versions of beans. For example, below is just v1.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:web-services="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="loginServiceV1" class="com.asi.v1.ext.api.service.impl.LoginServiceImpl">
<property name="restTemplate" ref="restTemplate" />
<property name="loginAPIUrl" value="${ws.api.login}" />
<property name="authorizationKey" value="${ws.api.login.doorman.key}" />
<property name="authorizationScheme" value="${ws.api.login.doorman.auth.scheme}" />
<property name="grantTypeKey" value="${ws.api.login.doorman.auth.grant_type.key}" />
<property name="grantTypeValue" value="${ws.api.login.doorman.auth.grant_type.value}" />
<property name="appCodeKey" value="${ws.api.login.doorman.auth.app_code.key}" />
<property name="appCodeValue" value="${ws.api.login.doorman.auth.app_code.value}" />
<property name="appVersionKey" value="${ws.api.login.doorman.auth.app_version.key}" />
<property name="appVersionValue" value="${ws.api.login.doorman.auth.app_version.value}" />
</bean>
<bean id="batchServiceV1" class="com.asi.v1.ext.api.service.impl.BatchServiceImpl">
<property name="restTemplate" ref="restTemplate" />
<property name="createBatchURL" value="${ws.api.batch.create}" />
<property name="finalizeBatchURL" value="${ws.api.batch.finalize}" />
</bean>
<bean id="productServiceClientV1" class="com.asi.v1.service.product.client.ProductClient">
<property name="productSearchUrl" value="${ws.api.product.import}" />
<property name="scheme" value="${ws.api.authorization.scheme}" />
</bean>
<bean id="throttlerV1" class="com.asi.v1.ext.api.service.impl.ThrottleService">
<property name="radarLoginService" value="${ws.api.throttle.radar.validate.token.url}" />
<property name="throttleRequest" value="${ws.api.throttle.required}" />
<property name="maximumRequests" value="${ws.api.throttle.maximum.requests}" />
<property name="maximumWaitCalendarField" value="${ws.api.throttle.wait.time.field}" />
<property name="maximumWaitHours" value="${ws.api.throttle.wait.time}" />
<property name="restTemplate" ref="restTemplate"/>
</bean>
<!-- <bean id="loginService" class="com.asi.v1.service.resource.LoginService">
<property name="loginAPIUrl" value="${ws.api.login}"></property>
</bean> -->
<!-- <bean id="lookupDataStore" class="com.asi.v1.ext.api.product.transformers.ProductDataStore">
<property name="lookupRestTemplate" ref="restTemplate"/>
<property name="lookupConverter" ref="jsonlookupConvertor" />
</bean>
<bean id="jsonlookupConvertor" class="com.asi.v1.ext.api.util.JsonToLookupTableConverter">
<property name="lookupRestTemplate" ref="restTemplate"/>
</bean> -->
<bean id="lookupValuesClientV1" class="com.asi.v1.service.product.client.LookupValuesClient">
<property name="lookupRestTemplate" ref="restTemplate"/>
<property name="lookupColorURL" value="${lookup.color.url}"></property>
<property name="lookupSizeURL" value="${lookup.sizes.url}"></property>
<property name="lookupMaterialURL" value="${lookup.material.url}"></property>
<property name="lookupcriteriaAttributeURL" value="${lookup.sizes.criteria.url}"></property>
<property name="originLookupURL" value="${lookup.orgin.url}"></property>
<property name="lookupCategoryURL" value="${lookup.product.categories.url}"></property>
<property name="lookupArtworkURL" value="${lookup.imprint.artwork.url}"></property>
<property name="lookupImprintURL" value="${lookup.imprint.url}"></property>
<property name="lookupTradeNameURL" value="${lookup.product.trade.names.url}"></property>
<property name="lookupShapeURL" value="${lookup.product.shapes.url}"></property>
<property name="lookupPackageURL" value="${lookup.packaging.url}"></property>
</bean>
<bean id="lookupParserV1" class="com.asi.v1.ext.api.integration.lookup.parser.LookupParser">
<!-- <property name="lookupClient" ref="lookupValuesClient"/> -->
<!-- <property name="imprintParser" ref="imprintMethodParser"/> -->
</bean>
<bean id="criteriasParser" class="com.asi.v1.ext.api.integration.lookup.parser.CriteriaSetParser">
<!-- <property name="productLookupParser" ref="lookupParser"/> -->
</bean>
<bean id="productConfigurationParser" class="com.asi.v1.ext.api.integration.lookup.parser.ProductConfigurationsParser">
<property name="productLookupParser" ref="lookupParser"/>
</bean>
<bean id="configurationParserV1" class="com.asi.v1.ext.api.integration.lookup.parser.ConfigurationsParser">
<!-- <property name="productLookupParser" ref="lookupParser"/> -->
</bean>
<bean id="imprintMethodParserV1" class="com.asi.v1.ext.api.integration.lookup.parser.ImprintParser">
<!-- <property name="criteriaLookupParser" ref="criteriasParser"/>
<property name="lookupsParser" ref="lookupParser"/> -->
</bean>
<bean id="productServiceV1" class="com.asi.v1.ext.api.service.impl.ProductServiceImpl">
</bean>
<bean id="productRepoV1" class="com.asi.v1.core.repo.product.ProductRepo">
<!-- <property name="productClient" ref="productServiceClient"/> -->
<!-- <property name="productConfiguration" ref="productConfigurationParser"/> -->
<!-- <property name="configurationParser" ref="configurationParser"/> -->
<!-- <property name="imprintParser" ref="imprintMethodParser"/> -->
<!-- <property name="productRestTemplate" ref="restTemplate"/> -->
<property name="productImportURL" value="${ws.api.product.import}"></property>
<property name="batchProcessingURL" value="${lookup.batch.processing}"></property>
<!-- <property name="lookupDataStore" ref="lookupDataStore" /> -->
<!-- <property name="lookupsParser" ref="lookupParser"/> -->
</bean>
<!-- To enable #RequestMapping process on type level and method level -->
<bean id="productDetailV1" class="com.asi.v1.service.product.client.vo.ProductDetail"/>
</beans>
This issue was never there until i was using Java 7 version when I switched it to Java 8 then I am seeing this exception. Due to limitation of this editor I cannot paste the entire exception log. Will paste in comments if you need.
Can anyone help me with this issue?
Try value="java.nio.charset.StandardCharsets.UTF_8" instead of value="#{T(java.nio.charset.Charset).forName('UTF-8')}". You would also need to name your parameters otherwise Spring won't be able to instantiate the MediaType since multiple constructors with 3 parameters exist.
You can try the following code :
<bean class="org.springframework.http.MediaType" >
<constructor-arg name="type" value="application" />
<constructor-arg name="subtype" value="json" />
<constructor-arg name="charset" value="#{T(java.nio.charset.StandardCharsets).UTF_8}"/>
</bean>
Thank you #louis-f for pointing out the issue and providing the solution. I tried to resolve this issue with the above suggestions but it was still giving the same exceptions.
Then I tried following and it resolves my issue:
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg name="type" value="application"/>
<constructor-arg name="subtype" value="json"/>
<constructor-arg name="charset" value="UTF-8" />
</bean>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg name="defaultCharset" value="UTF-8" />
</bean>
</list>
</property>
</bean>
So, what I actually did is just changed the charset constructor argument to string value i.e. "UTF-8" and it did worked for me.
On the application debugging - I checked the object restTemplate in inspect element and now I have everything coming properly for the messageConverters list.
Thanks again.

Two session Factories found when one was expected

I have referred to the question asked at Hibernate using multiple databases. My problem is similar but I am facing a different problem.I created two xml file each has a separate datasource and session factory.
In my web.xml I have
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>*The xml files* </param-value>
Once I run the project,the various loadings and the bindings are done from both the xml files.The various annotations and databases/tables are properly identified.But just after this is done before the control even goes outside.I get the following error.
main ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'daoEager' defined in URL [jar:file:/C:/Users/.../.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/infobutton-service/WEB-INF/lib/core-data-1.0.0-SNAPSHOT.jar!/.../DaoHibernateEagerImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : No unique bean of type [org.hibernate.SessionFactory] is defined: expected single matching bean but found 2: [sessionFactory, profilesessionFactory]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.hibernate.SessionFactory] is defined: expected single matching bean but found 2: [sessionFactory, profilesessionFactory]
The class DaoHibernateEagerImpl is
#Implementation
#Repository("daoEager")
public class DaoHibernateEagerImpl extends DaoHibernateImpl
{
// ========================= CONSTANTS =================================
/**
* A logger that helps identify this class' printouts.
*/
private static final Logger log = getLogger(DaoHibernateEagerImpl.class);
// ========================= CONSTRUCTORS ==============================
/**
* Required for a Spring DAO bean.
*
* #param sessionFactory
* Hibernate session factory
*/
#Autowired
public DaoHibernateEagerImpl(final SessionFactory sessionFactory)
{
super(sessionFactory);
}
// ========================= DEPENDENCIES ==============================
// ========================= IMPLEMENTATION: Dao =======================
// ========================= IMPLEMENTATION: SearchEngine ==============
}
One of the xml files is
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<context:annotation-config />
<!--
Data source: reads a properties file and injects them into a DBCP DS
Second datasource for Resource Profiles
-->
<bean id="profiledataSource"
class=".....ConfigurableBasicDataSource">
<constructor-arg index="0">
<bean class="org.apache.commons.dbcp.BasicDataSource" />
</constructor-arg>
<property name="properties">
<bean
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>WEB-INF/datasource-local.properties
</value>
</list>
</property>
</bean>
</property>
<!-- FUR-946: idle connections break. Adding connection testing. -->
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
</bean>
<!-- Session factory -->
<!-- Session Factory for the second datasource-->
<bean id="profilesessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="profiledataSource" />
<!--
Hibernate configuration properties (read from a properties file)
-->
<property name="hibernateProperties">
<bean
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>WEB-INF/hibernate.properties
</value>
<value>WEB-INF/datasource-local.properties
</value>
</list>
</property>
</bean>
</property>
<!-- Using improved naming strategy -->
<property name="namingStrategy">
<bean class="org.hibernate.cfg.DefaultNamingStrategy" />
</property>
<!-- Mapping annotated classes using search patterns -->
<property name="annotatedClasses">
<list>
<value><![CDATA[....profiledb.domain.Profiles]]></value>
</list>
</property>
</bean>
<!-- Hibernate data access template -->
<bean id="profilehibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="profilesessionFactory" />
</bean>
<tx:annotation-driven />
<!-- a PlatformTransactionManager is still required -->
<bean id="profiletransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="profilesessionFactory" />
</bean>
<bean id="profilesdbDao" class="....profiledb.service.ProfilesDaoImpl" >
<property name="sessionFactory" ref="profilesessionFactory"></property>
<context:component-scan base-package="....core.data" />
The other xml file is similar but has a different datasource and the session factory is
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
.....
The error message is pretty clear:
expected single matching bean but found 2: [sessionFactory, profilesessionFactory]
Which is understandable:
<bean id="profilesessionFactory"
<!-- ... -->
<bean id="sessionFactory"
The fix should be simple:
#Autowired
public DaoHibernateEagerImpl(
#Qualifier("profilesessionFactory") final SessionFactory sessionFactory)
If you cannot modify DaoHibernateEagerImpl class, you can always fall-back to XML-based configuration. First disable CLASSPATH scanning of DaoHibernateEagerImpl so that #Autowired is not picked up. Then simply write:
<bean class="DaoHibernateEagerImpl">
<constructor-arg ref="profilesessionFactory"/>
<!-- ... -->
</bean>
Finally you can take advantage of #Primary annotation / primary="true" directive:
<bean id="sessionFactory" primary="true">
<!-- ... -->
This will prefer sessionFactory when autowiring and there are two possibilities instead of throwing an exception.
Its because of...if you dont mention #Primary(annotation) / primary="true"(in xml config), Hiibernate does not know which sessionfactory to pick up.In that case it will give you the error mentioned. Just try with #Primary annotation it will work...

How do I configure dynamic weaving using EclipseLink & Spring?

How do I configure dynamic weaving using EclipseLink & Spring? Right now I'm trying to get this working with a Junit test, but I'll later have to have it work with Tomcat (my department has been standardized on it for something like 10 years).
I'm running into two main problems:
1. Spring wants a load time weaver:
Exception:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:181)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
<snip>
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavingEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [sun.misc.Launcher$AppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
<snip>
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [sun.misc.Launcher$AppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
<snip>
Caused by: java.lang.IllegalStateException: ClassLoader [sun.misc.Launcher$AppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
at org.springframework.context.weaving.DefaultContextLoadTimeWeaver.setBeanClassLoader(DefaultContextLoadTimeWeaver.java:91)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1437)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1408)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 44 more
I can fix this by configuring the Spring Instrumentation:
JVM parameter:
-javaagent:/path/to/org.springframework.instrument-3.1.0.M2.jar
2. Eclipselink is not satisfied with the Spring Instrumentation:
Error:
(similar error messages repeated many times)
[EL Severe]: 2011-06-20 16:12:57.951--ServerSession(979781372)--Local Exception Stack:
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------
Exception [EclipseLink-60] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [_persistence_set_shellType_vh] or [_persistence_get_shellType_vh] is not defined in the object [ps.entity.JudicialArtifactFamily].
Internal Exception: java.lang.NoSuchMethodException: ps.entity.JudicialArtifactFamily._persistence_get_shellType_vh()
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[shellType]
Descriptor: RelationalDescriptor(ps.entity.JudicialArtifactFamily --> [DatabaseTable(JUDICIAL_ARTIFACT_FAMILY)])
Exception [EclipseLink-218] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A NullPointerException would have occurred accessing a non-existent weaved _vh_ method [_persistence_get_shellType_vh]. The class was not weaved properly - for EE deployments, check the module order in the application.xml deployment descriptor and verify that the module containing the persistence unit is ahead of any other module that uses it.
I tried to fix this by using the EclipseLink weaver:
-javaagent:/dev/tools/javaagents/eclipselink.jar
But then I get the same exception from problem #1.
Library versions
I am using:
Java 1.6.0_24
EclipseLink 2.2.0.v20110202-r8913
Spring 3.1.0 M2
Configuration files
Here is my persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="eclipseLinkHashPU" transaction-type="RESOURCE_LOCAL">
<class>ps.entity.Artifact</class>
<class>ps.entity.JudicialArtifactFamily</class>
<class>ps.entity.ShellType</class>
<class>ps.entity.SourceArtifact</class>
<class>ps.entity.Health</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
</properties>
</persistence-unit>
</persistence>
Here is my application.xml:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jaxrs="http://cxf.apache.org/schema/jaxrs" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://cxf.apache.org/schema/jaxrs
http://cxf.apache.org/schema/jaxrs.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
<context:component-scan base-package="ps">
</context:component-scan>
<context:load-time-weaver/>
<alias alias="entityManagerFactory" name="eclipseLinkEntityManagerFactory"/>
<bean id="eclipseLinkEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:eclipselink-persistence.xml" />
<property name="persistenceUnitName" value="eclipseLinkHashPU" />
<property name="jpaPropertyMap">
<map>
<entry key="eclipselink.logging.level" value="Severe"/>
<entry key="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>
<entry key="javax.persistence.nonJtaDataSource" value-ref="hash1DataSource"/>
<!-- it's not good that I'm turning weaving off -->
<!-- <entry key="eclipselink.weaving" value="false"/> -->
</map>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform" value="oracle" />
<property name="database" value="ORACLE" />
<property name="generateDdl" value="true" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
<!-- datasources, etc -->
</beans>
For weaving with Spring I believe you need something like,
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="defaultDataSource" ref="dataSource" />
<property name="dataSources">
<map>
<entry>
<key>
<value>jdbc/__default</value>
</key>
<ref bean="dataSource" />
</entry>
<entry>
<key>
<value>jdbc/jta</value>
</key>
<ref bean="dataSource" />
</entry>
</map>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
There is some information here,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/JPASpring
Ensure you are not accessing your classes before accessing the Spring context.
Another solution is to use static weaving.
Now, I am also using EclipseLink 2.2 and Spring 3.1 as below. My configuration is a little different with yours.
There is no loadTimeWeaver configuration in your eclipseLinkEntityManagerFactory. I think, it will be ok if you use as below.
Please, try as below with your Oracle DB information..
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:faces="http://www.springframework.org/schema/faces"
xmlns:int-security="http://www.springframework.org/schema/integration/security"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:sec="http://www.springframework.org/schema/security"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration/security http://www.springframework.org/schema/integration/security/spring-integration-security-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="your-package"/>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="your-driver"/>
<property name="url" value="your-database-url"/>
<property name="username" value="your-username"/>
<property name="password" value="your-passowrd"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!-- <property name="dataSource" ref="dataSource"/>-->
<property name="persistenceUnitName" value="your-persistence-unit-name"/>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect"/>
</property>
<property name="jpaPropertyMap">
<props>
<prop key="eclipselink.weaving">false</prop>
</props>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver">
</bean>
</property>
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.OraclePlatform" />
<property name="generateDdl" value="false"/>
<property name="showSql" value="true"/>
</bean>
</beans>
copy org.springframework.instrument-3.1.0.M2.jar into tomcat/lib directory and try it again.
Considering the instrumentation for unit tests, one can add it as VM argument to the maven-surefire-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-javaagent:lib/test/spring-instrument-4.0.2.RELEASE.jar</argLine>
</configuration>
</plugin>
assuming spring-instrument jar was placed at corresponding location.
(For that, the following dependency could be added temporarily to the project pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<scope>test</scope>
</dependency>
and then after the build, the corresponding artifact copied from local .m2 directory to project's lib/test directory.)

Categories

Resources