I am using Spring 3.0.5.Release MVC for exposing a webservice and below is my 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"
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">
<!-- To enable #RequestMapping process on type level and method level -->
<context:component-scan base-package="com.pyramid.qls.progressReporter.service" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="marshallingConverter" />
<ref bean="atomConverter" />
<ref bean="jsonConverter" />
</list>
</property>
</bean>
<bean id="marshallingConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<constructor-arg ref="jaxbMarshaller" />
<property name="supportedMediaTypes" value="application/xml"/>
</bean>
<bean id="atomConverter" class="org.springframework.http.converter.feed.AtomFeedHttpMessageConverter">
<property name="supportedMediaTypes" value="application/atom+xml" />
</bean>
<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json" />
</bean>
<!-- Client -->
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<ref bean="marshallingConverter" />
<ref bean="atomConverter" />
<ref bean="jsonConverter" />
</list>
</property>
</bean>
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.pyramid.qls.progressReporter.impl.BatchProgressMetricsImpl</value>
<value>com.pyramid.qls.progressReporter.datatype.InstrumentStats</value>
<value>com.pyramid.qls.progressReporter.datatype.InstrumentInfo</value>
<value>com.pyramid.qls.progressReporter.datatype.BatchProgressMetricsList</value>
<value>com.pyramid.qls.progressReporter.datatype.LoadOnConsumer</value>
<value>com.pyramid.qls.progressReporter.datatype.HighLevelTaskStats</value>
<value>com.pyramid.qls.progressReporter.datatype.SessionStats</value>
<value>com.pyramid.qls.progressReporter.datatype.TaskStats</value>
<value>com.pyramid.qls.progressReporter.datatype.ComputeStats</value>
<value>com.pyramid.qls.progressReporter.datatype.DetailedInstrumentStats</value>
<value>com.pyramid.qls.progressReporter.datatype.ImntHistoricalStats</value>
</list>
</property>
</bean>
<bean id="QPRXmlView" class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg ref="jaxbMarshaller" />
</bean>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml"/>
<entry key="html" value="text/html"/>
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</list>
</property>
</bean>
<bean id="QPRController" class="com.pyramid.qls.progressReporter.service.QPRController">
<property name="jaxb2Mashaller" ref="jaxbMarshaller" />
</bean>
</beans>
Following is what i am doing in controller (QPRController)
#RequestMapping(value = "/clientMetrics/{clientId}", method = RequestMethod.GET)
public ModelAndView getBatchProgressMetrics(#PathVariable String clientId) {
List<BatchProgressMetrics> batchProgressMetricsList = null;
batchProgressMetricsList = batchProgressReporter.getBatchProgressMetricsForClient(clientId);
BatchProgressMetricsList batchList = new BatchProgressMetricsList(batchProgressMetricsList);
ModelAndView mav = new ModelAndView("QPRXmlView", BindingResult.MODEL_KEY_PREFIX + "batchProgressMetrics", batchList);
return mav;
}
This is what my batchprogressmetricsList looks like:
#XmlRootElement(name = "batchProgressMetrics")
public class BatchProgressMetricsList implements Serializable{
private int count;
private List<BatchProgressMetrics> batchProgressMetricsList;
public BatchProgressMetricsList() {
}
public BatchProgressMetricsList(List<BatchProgressMetrics> batchProgressMetricsList) {
this.batchProgressMetricsList = batchProgressMetricsList;
this.count = batchProgressMetricsList.size();
}
public int getCount() {
return count;
}
#XmlElement(name = "batchProgressMetrics1")
public List<BatchProgressMetrics> getBatchProgressMetrics() {
return batchProgressMetricsList;
}
Now i get the following:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'QPRController' defined in ServletContext resource [/WEB-INF/rest-servlet.xml]: Cannot resolve reference to bean 'jaxbMarshaller' while setting bean property 'jaxb2Mashaller'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jaxbMarshaller' defined in ServletContext resource [/WEB-INF/rest-servlet.xml]: Invocation of init method failed; nested exception is org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
com.pyramid.qls.progressReporter.iface.BatchProgressMetrics is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at com.pyramid.qls.progressReporter.iface.BatchProgressMetrics
at public java.util.List com.pyramid.qls.progressReporter.datatype.BatchProgressMetricsList.getBatchProgressMetrics()
at com.pyramid.qls.progressReporter.datatype.BatchProgressMetricsList
com.pyramid.qls.progressReporter.iface.BatchProgressMetrics does not have a no-arg default constructor.
this problem is related to the following location:
at com.pyramid.qls.progressReporter.iface.BatchProgressMetrics
at public java.util.List com.pyramid.qls.progressReporter.datatype.BatchProgressMetricsList.getBatchProgressMetrics()
at com.pyramid.qls.progressReporter.datatype.BatchProgressMetricsList
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
Previously i got this without the change.
SEVERE: Servlet.service() for servlet rest threw exception
javax.servlet.ServletException: Unable to locate object to be marshalled in model: {org.springframework.validation.BindingResult.batchProgressMetrics=
Note that BatchProgressMetrics is an interface so my MAV is returning list of BatchProgressMetrics objects and i have entry for its impl in classes to be bound in servlet.xml.
Can you please help me as to what i am doing wrong. And yes if i send just batchProgressMetricsList.get(0) in MAV it just works fine.
This because the JAXB context doesn't know how to handle lists of objects, only the objects themselves. It makes sense when you think about it - the only way to represent a list in XML is to wrap it in a container element, and it has no information as to how to do that.
So you need to define a class which is the container for the list of BatchProgressMetrics, and return that in the model instead.
Related
I have a dao package where all my DaoClasses implements amongst others the following methode:
public class XDaoImpl implements XDao {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
#Override
public void saveOrUpdate(MyObject o) {
//Transaction trans = getSessionFactory().getCurrentSession().beginTransaction();
getSessionFactory().getCurrentSession().saveOrUpdate(o);
//trans.commit();
}
}
If I run my application it needs a lot time to store my objects to the database. I belief it happens because I create a new Transaction for each object. So I tried to use Spring Frameworkâs xml based declarative transaction implementation. But till now it does not work for me:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
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.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/resources/spring/config/database.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="hibernate3SessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>/resources/spring/config/A.hbm.xml</value>
<value>/resources/spring/config/B.hbm.xml</value>
<value>/resources/spring/config/C.hbm.xml</value>
<value>/resources/spring/config/D.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="dBo" class="com.model.bo.DBoImpl">
<property name="dDao" ref="dDao" />
<property name="bDao" ref="bDao" />
</bean>
<bean id="dDao" class="com.model.dao.dDaoImpl">
<property name="sessionFactory" ref="hibernate3SessionFactory" />
</bean>
<bean id="aBo" class="com.model.bo.aBoImpl">
<property name="aDao" ref="aDao" />
<property name="bDao" ref="bDao" />
<property name="cDao" ref="cDao" />
</bean>
<bean id="bDao" class="com.model.dao.bDaoImpl">
<property name="sessionFactory" ref="hibernate3SessionFactory" />
</bean>
<bean id="cDao" class="com.model.dao.cDaoImpl">
<property name="sessionFactory" ref="hibernate3SessionFactory" />
</bean>
<bean id="aDao" class="com.model.dao.aDaoImpl">
<property name="sessionFactory" ref="hibernate3SessionFactory" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernate3SessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="boMethods" expression="execution(* com.model.bo.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="boMethods" />
</aop:config>
</beans>
The error that is thrown:
class org.springframework.beans.factory.BeanCreationException Error
creating bean with name 'dataSource' defined in class path resource
[resources/spring/config/BeanLocations.xml]: BeanPostProcessor before
instantiation of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0':
Cannot resolve reference to bean 'boMethods' while setting bean
property 'pointcut'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'boMethods': Instantiation of bean failed;
nested exception is java.lang.NoClassDefFoundError:
org/aspectj/weaver/BCException
public class DBoImpl implements DBo {
private DDao dDao;
private BDao bDao;
public DDao getDDao() {
return dDao;
}
public void setDDao(DDao dDao) {
this.dDao = dDao;
}
public BDao getbDao() {
return bDao;
}
public void setbDao(BDao bDao) {
this.bDao = bDao;
}
public D add(D r) {
dDao.saveOrUpdate(r);
return r;
}
}
It looks like you don't have the AOP jar files in your class path.
See:
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html
Look for the section "10.2.1 Enabling #AspectJ Support"
Using AOP for transactional behavior is fine. I'd suggest having a look at annotation based configuration (Note the <tx:annotation-driven transaction-manager="transactionManager" />), which might be a little bit more straightforward.
Furthermore I would be careful about using this configuration. A transaction is meant to encapsulate an atomic unit of work. Having a method like saveOrUpdate(EntityType entity) I'd think your atomic unit of work was saving one entity, not saving n entities. The longer a transaction runs, the greater gets the probability of running into deadlocks.
I'd suggest creating a Method like public void saveOrUpdateInBatch(MyObject... objects). The name implies you are dealing with an atomic operation which handles a number of elements. Also you might want to optimize this method for batch inserts.
I have this maven project with its modules
Parent
|_____Model
|_____Persistence
|_ persistence-context.xml
|_____Service
|_ service-context.xml
|_____View
|_ spring/app-config.xml
And in persistence-context.xml have the next:
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
default-autowire="byName">
<tx:annotation-driven transaction-manager="persistence.transactionManager" proxy-target-class="true" />
<bean id="persistence.propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:META-INF/jdbc.properties</value>
<value>classpath*:META-INF/hibernate.properties</value>
</list>
</property>
</bean>
<bean id="persistence.transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="persistence.sessionFactory" />
<property name="jdbcExceptionTranslator" ref="persistence.jdbcExceptionTranslator" />
</bean>
<bean name="persistence.jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
<constructor-arg>
<ref bean="persistence.dataSource" />
</constructor-arg>
</bean>
<bean id="persistence.dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.db.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="defaultAutoCommit" value="false" />
<property name="poolPreparedStatements" value="true" />
<property name="initialSize" value="20" />
<property name="maxActive" value="30" />
<property name="maxIdle" value="25" />
</bean>
<bean id="persistence.sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="persistence.dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
</props>
</property>
<property name="mappingLocations">
<list>
<value>classpath:mappings/items/servicio.hbm.xml</value>
<value>classpath:mappings/items/stockable.hbm.xml</value>
<value>classpath:mappings/items/bigstockable.hbm.xml</value>
</list>
</property>
</bean>
<!-- Daos beans -->
<bean id="servicioDao" class="daos.ServicioDao" >
<property name="sessionFactory" ref="persistence.sessionFactory" />
</bean>
<bean id="stockableDao" class="daos.StockableDao" >
<property name="sessionFactory" ref="persistence.sessionFactory" />
</bean>
<bean id="bigStockableDao" class="daos.BigStockableDao" >
<property name="sessionFactory" ref="persistence.sessionFactory" />
</bean>
In that xml i make my daos with it sessionFactory, but when i startup the project i got java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required, because my hibernateTemplate is null.
My daos extends from HibernateDaoSupport and i know that if you give to your dao a sessionFactory it will create automatically an hibernateTemplate, and idk what could be happening.
My daos have a #Repository (example #Repository(value="servicioDao"))
And the services the #Service with the #Autowired in the setter
and i am adding them in the contex
<context:component-scan base-package="controllers" />
<context:component-scan base-package="servicios" />
<context:component-scan base-package="daos" />
I just add this in the persistence-context.xml
<!-- Daos beans -->
<bean id="servicioDao" class="daos.ServicioDao" >
<property name="sessionFactory" ref="persistence.sessionFactory" />
<property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>
<bean id="stockableDao" class="daos.StockableDao" >
<property name="sessionFactory" ref="persistence.sessionFactory" />
<property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>
<bean id="bigStockableDao" class="daos.BigStockableDao" >
<property name="sessionFactory" ref="persistence.sessionFactory" />
<property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>
I get the same error.
Some of my daos code:
#Repository(value="servicioDao")
#SuppressWarnings("serial")
public class ServicioDao extends GenericHome<Servicio>{
public ServicioDao(){}
#Override
protected Class<Servicio> getDomainClass() {
return Servicio.class;
}
}
public abstract class GenericHome<T> extends HibernateDaoSupport implements Serializable{
protected Class<T> persistentClass = this.getDomainClass();
protected abstract Class<T> getDomainClass();
}
public class ServicioService {
private ServicioDao servicioDao;
public ServicioService(){}
public ServicioDao getServicioDao() {
return servicioDao;
}
#Autowired
public void setServicioDao(ServicioDao servicioDao) {
this.servicioDao = servicioDao;
}
}
I noticed that when i use #Service and #Repository, beans arent created by the xml, so when it gave me the error "'sessionFactory' or 'hibernateTemplate' is required" was because the dao was created but never filled its sessionFactory, so to use my xml files i created the controller like a normal bean
Try changing your bean definitions for this:
<bean id="servicioDao" class="daos.ServicioDao" >
<constructor-arg>
<ref bean="persistence.sessionFactory" />
</constructor-arg>
</bean>
It means that you are passing the sessionFactory in the constructor of your DAO class.
You also have to write the full pass in your "class" parameter.
<bean id="servicioDao" class="full.package.path.to.ServicioDao" >
Next, in your DAO class write something like this:
#Repository
public class ServicioDao{
private SessionFactory sessionFactory;
public ServicioDao() {
}
/**
* Constructor.
*
* #since 1.0
*/
public ServicioDao(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
...
...
}
Finally, in your controllers, you can use the DAO class as follows:
...
#Autowired
ServicioDao servicioDao;
...
servicioDao.getServicioDao();
Notice that you don't need to make new ServicioDao();.
Do it for every DAO class.
I have a project in Java 1.6 and I have to pass in java 1.8.
I get this error :
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.amm.noc.telecom.reporting.services.TicketManager net.amm.noc.telecom.reporting.integration.itest.EndToEndTestCase.ticketManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [net.amm.noc.telecom.reporting.services.TicketManager] is defined: expected single matching bean but found 2: [ticketManager, proxiedTicketManagerImpl]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [net.amm.noc.telecom.reporting.services.TicketManager] is defined: expected single matching bean but found 2: [ticketManager, proxiedTicketManagerImpl]
Exception in thread "ActiveMQ ShutdownHook" java.lang.NoClassDefFoundError: org/apache/activemq/transport/vm/VMTransportFactory
at org.apache.activemq.broker.BrokerService.stop(BrokerService.java:518)
at org.apache.activemq.broker.BrokerService.containerShutdown(BrokerService.java:1754)
at org.apache.activemq.broker.BrokerService$4.run(BrokerService.java:1732)
Caused by: java.lang.ClassNotFoundException: org.apache.activemq.transport.vm.VMTransportFactory
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
... 3 more
My class test :
#ContextConfiguration(locations = { "classpath:/application-context.xml" })
public class EndToEndTestCase extends AbstractTestNGSpringContextTests {
#Autowired
#Qualifier("ticketManager")
private TicketManager ticketManager;
/**
* This test relies on the proxied ticketManager (stub) to send the NLV
* buffer on the bus. The deployed skeleton intercepts the message,
* transform it and delegates the process to the actual bean.
*/
#Test
public void test1() {...
And the appContext :
<!-- defines which bean are service requests delegated to -->
<alias name="proxiedTicketManagerImpl" alias="ticketManagerImpl" />
<!-- defines which bean are response requests delegated to -->
<alias name="proxiedTicketResponseImpl" alias="ticketResponseImpl" />
<bean id="telecomReportingMethodInvocationInterceptor"
class="net.amm.noc.integration.itest.MethodInvocationInterceptor">
<property name="channel" value="TICKET-MANAGER" />
</bean>
<bean id="proxiedTicketManagerImpl" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyTargetClass" value="true" />
<property name="target">
<bean
class="net.amm.noc.telecom.reporting.mock.TicketManagerMock">
<property name="ticketResponse" ref="ticketResponse" />
</bean>
</property>
<property name="interceptorNames">
<list>
<value>telecomReportingMethodInvocationInterceptor</value>
</list>
</property>
</bean>
<bean id="proxiedTicketResponseImpl" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyTargetClass" value="true" />
<property name="target">
<bean class="net.amm.noc.telecom.reporting.mock.TicketResponseMock" />
</property>
<property name="interceptorNames">
<list>
<value>telecomReportingMethodInvocationInterceptor</value>
</list>
</property>
</bean>
<bean id="ticketManager" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="interfaces" value="net.amm.noc.telecom.reporting.services.TicketManager" />
<property name="proxyInterfaces" value="net.amm.noc.telecom.reporting.services.TicketManager" />
<property name="target">
<bean class="java.lang.Object" />
</property>
<property name="interceptorNames">
<list>
<value>telecomReportingServiceInterceptor</value>
</list>
</property>
</bean>
<bean id="telecomReportingServiceInterceptor"
class="net.amm.noc.integration.client.aop.ServiceInterceptor">
<property name="serviceMessageEncoder" ref="telecomReportingEncoder" />
<property name="serviceCaller">
<bean class="net.amm.noc.integration.mep.client.MepServiceCaller">
<property name="responseListener" ref="telecomReportingResponseListener"></property>
<property name="contextFactory">
<bean
class="net.amm.noc.integration.mep.client.MepServiceClientContextFactory"
init-method="init">
<property name="serviceDefinition">
<bean
class="net.amm.noc.integration.mep.service.GenericServiceDefinition">
<property name="category" value="NOC" />
<property name="name" value="TEL_REPORT" />
</bean>
</property>
</bean>
</property>
</bean>
</property>
</bean>
Does anyone can help me solve this problem?
For information, it's OK with Java 1.6
Thank you.
I want to use a path parameter as a full ISO timestamp in a rest service.
http://domain:8080/ctx/someObj/2000-10-31 01:30:00.000-05:00
I previously had mvc:annotation driven turned on, but turned it off so i could set "useDefaultSuffixPattern" to false on the DefaultAnnotationHandlerMapping.
the controller code
#RequestMapping(value = "/lwc/{userMidnightTime}", method = RequestMethod.GET)
#ResponseBody
public List<ProgramSnippetView> getLiveWebcastsWithin24HoursOfTime(#PathVariable(value = "userMidnightTime") #DateTimeFormat(iso= DATE_TIME) Date userMidnightTime) {
Calendar cal = new GregorianCalendar();
cal.setTime(userMidnightTime);
cal.add(Calendar.HOUR, 24);
Date endTime = cal.getTime();
return programService.getLiveWebcastSnippetsWithProductionDateInRange(userMidnightTime, endTime);
}
I get the following error. I can see that the framework is ultimately calling the deprecated Date.parse() method with the correct String, instead of using joda time to do the work.
112977 [http-apr-8080-exec-7] DEBUG org.springframework.beans.BeanUtils - No property editor [java.util.DateEditor] found for type java.util.Date according to 'Editor' suffix convention
117225 [http-apr-8080-exec-7] DEBUG org.springframework.beans.TypeConverterDelegate - Construction via String failed for type [java.util.Date]
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.Date]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException
I want joda to parse the full ISO date, as is specified in the org.springframework.format.annotation.DateTimeFormat.java annotation file like so:
/**
* The most common ISO DateTime Format <code>yyyy-MM-dd'T'hh:mm:ss.SSSZ</code> e.g. 2000-10-31 01:30:00.000-05:00.
* The default if no annotation value is specified.
*/
DATE_TIME, .....
App Context config
<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:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="blah.blah"/>
<mvc:resources mapping="/resources/**" location="/resources/"/>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="formatterRegistrars">
<set>
<bean class="org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar">
<property name="useIsoFormat" value="true"/>
</bean>
</set>
</property>
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="0"/>
<property name="useDefaultSuffixPattern" value="false"/>
<!-- allows for periods in url -->
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="validator" ref="validator"/>
</bean>
</property>
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<!--<property name="writeAcceptCharset" value="false" />-->
</bean>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
</list>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="json" value="application/json"/>
</map>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="prefixJson" value="true"/>
</bean>
</list>
</property>
</bean>
<mvc:view-controller path="/" view-name="home"/>
One possible issue that I see is that you have not registered conversionService with handlerAdapter, you can do it this way:
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="conversionService" ref="conversionService"/>
<property name="validator" ref="validator"/>
</bean>
</property>
This is way too late (3 years, precisely), but it may help someone else.
The url is missing the time designator 'T', so try
http://domain:8080/ctx/someObj/2000-10-31T01:30:00.000-05:00
instead of
http://domain:8080/ctx/someObj/2000-10-31 01:30:00.000-05:00
in my web application developped with GWT, Hibernate ans Spring, I encounter when setting the jobClass bean in the application-context.xml file.
I get this error at runtime :
Error 500 Error creating bean with name 'schedulerFactory' defined in class path resource [application-context.xml]:
Cannot resolve reference to bean 'cronTrigger' while setting bean property 'triggers' with key [0];
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'cronTrigger' defined in class path resource [application-context.xml]:
Cannot resolve reference to bean 'exampleJob1' while setting bean property 'jobDetail';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'exampleJob1' defined in class path resource [application-context.xml]:
Initialization of bean failed;
nested exception is org.springframework.beans.TypeMismatchException:
Failed to convert property value of type [fr.web.utils.ExampleJob] to required type [java.lang.Class] for property 'jobClass';
nested exception is java.lang.IllegalArgumentException:
Cannot convert value of type [fr.web.utils.ExampleJob] to required type [java.lang.Class] for property 'jobClass':
PropertyEditor [org.springframework.beans.propertyeditors.ClassEditor] returned inappropriate value
Here is my Java class :
public class ExampleJob extends QuartzJobBean {
private AbsenceDao absenceDao;
#Override
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
List untreatedDemands = new ArrayList();
untreatedDemands = absenceDao.getDemandsAskedNotValidated();
}
public AbsenceDao getAbsenceDao() {
return absenceDao;
}
public void setAbsenceDao(AbsenceDao absenceDao) {
this.absenceDao = absenceDao;
}
}
and here is my application-context.xml :
<!-- variables d'environnement - fichier properties -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="placeholderconfig">
<property name="fileEncoding" value="UTF-8"/>
<property name="locations">
<list>
<value>classpath:internal.properties</value>
</list>
</property>
</bean>
<!-- Configuration du crontrigger -->
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref local="exampleJob1" />
</property>
<property name="cronExpression">
<util:constant static-field="fr.web.utils.APP_VAR.CRON_EXPRESSION" />
</property>
</bean>
<bean id="jobClass" class="fr.web.utils.ExampleJob">
<property name="absenceDao" ref="absenceDao"/>
</bean>
<bean id="exampleJob1" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" ref="jobClass" />
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5" />
</map>
</property>
</bean>
<tx:annotation-driven transaction-manager="hibernateTransactionManager"/>
<!-- Bean containing all the properties of the application -->
<bean class="fr.web.utils.ApplicationProperties" id="applicationProperties" lazy-init="true" scope="singleton">
<constructor-arg index="0" value="classpath:internal.properties"/>
</bean>
<!-- Bean DAO -->
<bean abstract="true" id="abstractDao">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean class="fr.web.dao.AbsenceDao" id="absenceDao" parent="abstractDao"/>
</bean>
</beans>
property jobClass requires class and you have given reference of bean , So change
<bean id="exampleJob1" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" ref="jobClass" />
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5" />
</map>
</property>
</bean>
to (Note : value attribute below)
<bean id="exampleJob1" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="fr.acensi.web.utils.ExampleJob" />
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5" />
</map>
</property>
</bean>
There is another option here which you may think neater or not, I like it as it keeps the context a bit cleaner.
<bean id="exampleJob1" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<bean factory-bean="jobClass" factory-method="getClass" />
</property>
</bean>
the breakdown of the problem is as Jigar Joshi describes solution is slighty different.
It allows you to keep you bean jobClass instantiation seperate from the building of the JobDetailbean.