How to resolve Spring Batch Error? - java

I am trying to learn Spring batch for writing batch jobs in java. So i am using this tutorial.
Now the problem is after I have used all the jars, i started executing the project . This left me with a devious error :
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#1e7b1e7b: defining beans [jobLauncher,jobRepository,transactionManager,wordsFWTasklet,numbersFWTasklet,taskletStep,fileWritingJob]; root of factory hierarchy
Sep 3, 2013 8:09:29 AM org.springframework.batch.core.launch.support.CommandLineJobRunner start
SEVERE: Job Terminated in error: Error creating bean with name 'fileWritingJob' defined in class path resource [fileWritingJob.xml]: Initialization of bean failed; nested exception is java.lang.NullPointerException
Throwable occurred: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileWritingJob' defined in class path resource [fileWritingJob.xml]: Initialization of bean failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
Caused by: java.lang.NullPointerException
at org.springframework.core.GenericTypeResolver.getTypeVariableMap(GenericTypeResolver.java:144)
at org.springframework.core.GenericTypeResolver.resolveReturnType(GenericTypeResolver.java:93)
In case, you want to know the code that i have used for my configuration xml, it's below :
fileWritingJob.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="applicationContext.xml"/>
<bean id="wordsFWTasklet" class="FileCreatorTasklet">
<property name="filePath" value="C:\\temp\\words.txt"/>
<property name="content" value="abcdefghijklmnopqrstuwxyz"/>
</bean>
<bean id="numbersFWTasklet" class="FileCreatorTasklet">
<property name="filePath" value="C:\\temp\\numbers.txt"/>
<property name="content" value="0123456789"/>
</bean>
<bean id="taskletStep" abstract="true"
class="org.springframework.batch.core.step.tasklet.TaskletStep">
<property name="jobRepository" ref="jobRepository"/>
</bean>
<bean id="fileWritingJob" class="org.springframework.batch.core.job.SimpleJob">
<property name="name" value="fileWritingJob" />
<property name="steps">
<list>
<bean parent="taskletStep">
<property name="tasklet" ref="wordsFWTasklet"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean parent="taskletStep">
<property name="tasklet" ref="numbersFWTasklet"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
</list>
</property>
<property name="jobRepository" ref="jobRepository"/>
</bean>
</beans>
EDIT :
ApplicationContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository"/>
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.SimpleJobRepository">
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapJobInstanceDao"/>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapStepExecutionDao"/>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapExecutionContextDao"/>
</constructor-arg>
</bean>
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>
</beans>
Can any one tell me what am i doing wrong here ?

Which versione of spring-batch are you using? With 2.2.1.RELEASE (and 3.2.3.RELEASE of Spring framework) this example works fine!
Libraries (from maven) are:
org.springframework
spring-core
spring-beans
spring-context
spring-batch-core
spring-batch-infrastructure

Related

Getting compile error while using <context:component-scan> annotation in spring xml

I am trying to annotation to auto-wire but getting compile error, I am not able to get the error message, there is only red cross at that line in spring XML. where I am doing wrong?
spring.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd"
xmlns:context="http://www.springframework.org/schema/context/">
<!--commenting it out as we are using component annotation for this class-->
<!-- <bean id="circle" class="org.devesh.learning.spring.Circle">
</bean>
-->
<bean id ="pointA" class="org.devesh.learning.spring.Point">
<property name="x" value="${pointA.pointX}"></property>
<property name="y" value="${pointA.pointY}"></property>
</bean>
<bean id = "center" class="org.devesh.learning.spring.Point">
<property name="x" value="20"></property>
<property name="y" value="0"></property>
</bean>
<bean id = "pointC" class="org.devesh.learning.spring.Point">
<qualifier value="circle related"></qualifier>
<property name="x" value="-20"></property>
<property name="y" value="0"></property>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="pointconfig.properties"></property>
</bean>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"></bean>
<context:component-scan base-package="org.devesh.learning.spring"/>
</beans>
Is it a possible typo?
as is:
xmlns:context="http://www.springframework.org/schema/context/
to be :
xmlns:context="http://www.springframework.org/schema/context

Hibernate with Springs .hbm.xml filenotfoundException

I am using netbeans IDE, I am integrating hibernate with springs. I am getting the following exception when I run the program:
Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [Employee.hbm.xml] cannot be opened because it does not exist
This my applicationContext.xml file:
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"></property>
<property name="url" value="jdbc:derby://localhost:1527/sample"></property>
<property name="username" value="app"></property>
<property name="password" value="app"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<value>Employee.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="template" class="org.springframework.orm.hibernate4.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean class="com.office.businessLayer.Security" id="security">
</bean>
<bean id="dao" class="com.office.dao.EmployeeDao">
<property name="template" ref="template"/>
</bean>
</beans>
I have tried every possible solution on the internet but the exception still remains. Can somebody please help with this?
This is the project directory:
Put your Employee.hbm.xml file in the same package that Employee.java resides and leave your mappingResources config as is (<value>Employee.hbm.xml</value>).
if your employee.hbm.xml is at root of application, your mapping resource should be something like this.
<property name="mappingResources">
<list>
<value>classpath:Employee.hbm.xml</value>
</list>
</property>

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.

Spring throws exception trying to resolve property placeholder using a Jasypt encrypted property placeholder

I am trying to load encrypted properties using Jasypt's EncryptablePropertyPlaceholderConfigurer.
Here is my application context, with the offending bean and the encrypted property placeholder bean:
<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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder/>
<bean class="com.blahblah.OffendingBean">
<property name="user" value="${my.user}"/>
<property name="password" value="${my.password}"/>
</bean>
<bean id="propertyConfigurer"
class="org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="configurationEncryptor"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>credentials.properties</value>
</list>
</property>
</bean>
<bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config" ref="environmentVariablesConfiguration"/>
</bean>
<bean id="environmentVariablesConfiguration"
class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
<property name="algorithm" value="PBEWithMD5AndDES"/>
<property name="password" value="not telling you"/>
</bean>
</beans>
Note I have <property name="ignoreUnresolvablePlaceholders" value="true"/> set for the property placeholder.
I have stepped through this in the debugger, and it seems like another Property Placeholder instance is coming from somewhere and deciding ${my.user} is not set anywhere and throws an exception.
The weird thing is this was working just fine - I do not know what I changed that broke this.
Pretty sure the prop file "credentials.properties" is being found - EncryptablePropertyPlaceholderConfigurer is not complaining about it. It definitely has the property my.user defined in it. Even Intellij is doing the substitution in the editor!
side note, don't think it is relevant, but this spring context is being loaded via a Jersey 2 servlet context.
Here is the exception:
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'com.blahblah.OffendingBean#0' defined in class path resource [applicationContext.xml]: Could not resolve placeholder 'my.user' in string value "${my.user}"
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:174)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:151)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:669)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at org.glassfish.jersey.server.spring.SpringComponentProvider.createXmlSpringConfiguration(SpringComponentProvider.java:164)
at org.glassfish.jersey.server.spring.SpringComponentProvider.createSpringContext(SpringComponentProvider.java:155)
at org.glassfish.jersey.server.spring.SpringComponentProvider.initialize(SpringComponentProvider.java:98)
whelp, this fixed it:
changed:
<context:property-placeholder/>
to
<context:property-placeholder ignore-unresolvable="true"/>
<bean id="propertyConfigurer"
class="org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="configurationEncryptor"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<!-- change it -->
<value>classpath:credentials.properties</value>
</list>
</property>
</bean>
<!-- add it -->
<context:property-placeholder location="classpath:jdbc.properties" />

HTTP Status 500 - Spring MVC unable to add interceptors

I'm getting an exception when I run this application on Tomcat 7 server. It runs perfectly fine when I don't add this piece of line on my dispatcherservlet.
<mvc:interceptors>
<bean class="com.spring.maria.interceptor.PerformanceMonitorInterceptor" />
</mvc:interceptors>
but when I add it. I get this error.
I doubled check for spelling errors. There is none. I'm not sure whats causing the issue.
DispatcherServlet.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:mvc="http://www.springframework.org/schema/mvc" xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<mvc:annotation-driven enable-matrix-variables="true" />
<context:component-scan base-package="com.spring.maria" />
<mvc:resources location="/resources/" mapping="/resources/**" />
<mvc:interceptors>
<bean class="com.spring.maria.interceptor.PerformanceMonitorInterceptor" />
</mvc:interceptors>
<!-- View Resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
<!-- File Uploading -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10240000" />
</bean>
<!-- Java Object Conversion to XML/JSON -->
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="defaultViews">
<list>
<ref bean="jsonView" />
<ref bean="xmlView" />
</list>
</property>
</bean>
<bean id="jsonView"
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="prettyPrint" value="true" />
</bean>
<bean id="xmlView"
class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>
com.spring.maria.domain.Product
</value>
</list>
</property>
</bean>
</constructor-arg>
</bean>
Root Cause Error
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': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
Ahh, I forgot to include {extends HandlerInterceptorAdapter}. Thank You. It works now.

Categories

Resources