MalformedParameterizedTypeException when running Mybatis App - spring

here's the stacktrace:
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
I used the libraries that came w/ the mybatis-spring 1.1.1 and I added the spring-web-3.1.1.RELEASE.jar. My IDE is JDeveloper 11.1.2.1.0. here's the contents of WEB-INF/lib
aopalliance-1.0.jar
commons-logging-1.1.1.jar
jettison-1.1.jar
mybatis-3.1.1.jar
mybatis-spring-1.1.1.jar
mybatis-spring-1.1.1-javadoc.jar
mybatis-spring-1.1.1-sources.jar
spring-aop-3.1.1.RELEASE.jar
spring-asm-3.1.1.RELEASE.jar
spring-batch-core-2.1.8.RELEASE.jar
spring-batch-infrastructure-2.1.8.RELEASE.jar
spring-beans-3.1.1.RELEASE.jar
spring-context-3.1.1.RELEASE.jar
spring-core-3.1.1.RELEASE.jar
spring-expression-3.1.1.RELEASE.jar
spring-jdbc-3.1.1.RELEASE.jar
spring-tx-3.1.1.RELEASE.jar
spring-web-3.1.1.RELEASE.jar
xpp3_min-1.1.4c.jar
xstream-1.3.jar
here's the contents of applicationContext.xml
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${driverClassName}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="ph.com.aub.util"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="ph.com.aub.mappers" />
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:jdbc.properties</value>
</property>
</bean>

I think you're using wrong libs: you should use mybatis-3.1.0
spring-mybatis-integration

Related

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'exampleFileMapper' is defined

I'm trying to implement an example of spring batch 2.1.9
the scenario is to have a flexibility to switch Writers based on some conditions.
i have one csv file as input and 4 csv file as output.
while runing my processor this error is occured
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'exampleFileMapper' is defined.
The problem is in this bean
<bean id="exampleFileSourceReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<property name="resource" value="file:#{jobParameters['file']}" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<!-- split it -->
<property name="lineTokenizer">
<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<!-- this is missing -->
<property name="delimiter" value=";"/>
<property name="names" value="institution,type,nom,rubrique,montantPaye,MontantRetenu" />
</bean>
</property>
<property name="fieldSetMapper">
<!-- map to an object -->
<bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
<property name="prototypeBeanName" value="exampleFileMapper" />
</bean>
</property>
</bean>
</property>
If anyone can explain to me what the operation of this line
<property name="prototypeBeanName" value="exampleFileMapper" />

Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'xaDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xaDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'xaDataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driverClassName' of bean class [org.postgresql.xa.PGXADataSource]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1091)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1980)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
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)
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
<bean id="requestHandler" class="org.dejach.marketServer.requesthandler.RequestHandler" init-method="init">
<property name="factory" ref="marketApiFactory"></property>
</bean>
<bean id="RequestProcessor" class="org.dejach.marketServer.processor.RequestProcessor">
<property name="handler" ref="requestHandler" />
</bean>
<bean id="marketApiFactory" class="org.dejach.marketServer.processor.MarketApiFactory">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>WEB-INF/marketApi.properties</value>
</property>
<property name="nullValue" value="#null" />
</bean>
<bean id="properties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="WEB-INF/marketApi.properties" />
</bean>
<bean id="dataSource" class="org.postgresql.xa.PGXADataSource">
<!-- <property name="pinGlobalTxToPhysicalConnection" value="true" /> -->
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="${jdbcUrl}" />
<property name="user" value="${username}" />
<property name="password" value="${password}" />
</bean>
<!-- configure an Atomikos JTA-aware datasource -->
<bean id="xaDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="xaDatasource" />
<property name="xaDataSource" ref="dataSource" />
<property name="poolSize" value="${poolSize}" />
</bean>
<!-- http://fogbugz.atomikos.com/default.asp?community.6.702.5 -->
<bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp"
init-method="init" destroy-method="shutdownForce">
<constructor-arg>
<props>
<prop key="com.atomikos.icatch.log_base_name">${com.atomikos.icatch.log_base_name}</prop>
<prop key="com.atomikos.icatch.log_base_dir">${com.atomikos.icatch.log_base_dir}</prop>
<prop key="com.atomikos.icatch.max_timeout">3600000</prop>
</props>
</constructor-arg>
</bean>
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close" depends-on="userTransactionService">
<property name="forceShutdown" value="false" />
<property name="startupTransactionService" value="true" />
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
<property name="transactionTimeout" value="${transactionTimeout}" />
</bean>
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"
depends-on="atomikosTransactionManager,atomikosUserTransaction">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="userTransaction" ref="atomikosUserTransaction" />
<property name="allowCustomIsolationLevels" value="true" />
</bean>
<bean id="jpaVendor"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="${showSql}" />
<property name="databasePlatform" value="${databasePlatform}" />
<property name="generateDdl" value="${generateDdl}" />
<property name="database" value="${database}" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="xaDataSource" />
<property name="packagesToScan" value="${marketPackage}" />
<property name="jpaVendorAdapter" ref="jpaVendor" />
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
</bean>
username=postgres
password=$$$$$$$
hibernate.hbm2ddl.auto=create
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
# package scan for entities
marketPackage=org.dejach
transactionTimeout=300
showSql=true
#databasePlatform=org.hibernate.dialect.MySQL5InnoDBDialect
databasePlatform=org.hibernate.dialect.PostgreSQLDialect
#database=org.springframework.orm.jpa.vendor.Database.MYSQL
#database=MYSQL
database=POSTGRESQL
generateDdl=false
poolSize=30
#XA datasource
#XADataSource=${mysqlDataSource}
XADataSource=${postgresqlDataSource}
#mysqlDataSource=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
postgresqlDataSource=org.postgresql.xa.PGXADataSource
H2xadatasource=org.h2.jdbcx.JdbcDataSource
postgresqlUrl = jdbc:postgresql://localhost:5432/ethiopianMarketdb
H2url=jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
jdbcUrl=${postgresqlUrl}
blobFieldName=xmlData
#Atomikus properties
#see http://www.atomikos.com/Documentation/JtaProperties com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
com.atomikos.icatch.console_file_name
#Specifies the console log level. Defaults to WARN. Should be one of: WARN, INFO or DEBUG.
com.atomikos.icatch.log_base_name=tmlog
com.atomikos.icatch.log_base_dir=target
#com.atomikos.icatch.log_base_dir=/transactionLogs/
#com.atomikos.icatch.tm_unique_name=
com.atomikos.icatch.max_timeout=3600000
I don't see a setter setDriverClassName(..) in following class
https://jdbc.postgresql.org/documentation/publicapi/org/postgresql/xa/PGXADataSource.html
So, it make sense to remove following property from xaDataSource and try once again
<property name="driverClassName" value="org.postgresql.Driver" />
BTW, I don't any setUrl either, so you should review the logic of creating your bean.
Here is the list of available setters:
setCompatible
setDatabaseName
setLoginTimeout
setLogLevel
setLogWriter
setPassword
setPortNumber
setPrepareThreshold
setProtocolVersion
setServerName
setSocketTimeout
setSsl
setSslfactory
setTcpKeepAlive
setUnknownLength
setUser
writeBaseObject

How to configure 2 databases in MyBatis using MyBatis-Spring

I am trying to configure 2 different datasources in my application as it is required.
My configuration in the AppContext.xml is as follows:
<bean id="dataSourceA" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="url" value="datasourceAURL"/>
<property name="username" value="aaaa"/>
<property name="password" value="pppp"/>
</bean>
<bean id="dataSourceB" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="url" value="datasourceBURL"/>
<property name="username" value="bbbb"/>
<property name="password" value="cccc"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com/ex/myBatis/mappings" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceA" />
<property name="typeAliasesPackage" value="com.ex.myBatis.entities"/>
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
<bean id="sqlSessionFactory1" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="configDataSource" />
<property name="typeAliasesPackage" value="com.ex.myBatis.entities"/>
</bean>
<bean id="sqlSession1" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory1" />
</bean>
<bean id="callService" class="com.ex.myBatis.Service.callService">
<property name="sqlSession" ref="sqlSession1" />
</bean>
But while accessing the bean I am getting the below Exception
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'callService': Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire method: public final void
org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionTemplate(org.mybatis.spring.SqlSessionTemplate);
nested exception is
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
qualifying bean of type [org.mybatis.spring.SqlSessionTemplate] is
defined: expected single matching bean but found 2:
sqlSession,sqlSession1
Please somebody help me in figuring out the issue.
Also please suggest me if there is someother way to configure 2 Datasources.
Your configuration is mostly correct. The problem you face is that you use autowiring to inject one of callService dependencies.
Seems that you use SqlSessionDaoSupport and its sqlSessionTemplate field is autowired. There are two templates defined so spring cannot automatically wire dependencies. You need specify correct template manually.

java.lang.ClassNotFoundException: org.hibernate.engine.SessionFactoryImplementor

i am trying to migrate to hibernate 4.1.0.Final with spring 3.1.1.RELEASE
and following is my configuration for hibernate:
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="${project.groupId}.domain" />
<!-- control the behavior of Hibernate at runtime,All are optional and
have reasonable default values -->
<property name="hibernateProperties">
<value>
<!-- hibernate.dialect: allows Hibernate to generate SQL optimized for
a particular relational database -->
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=create-drop
hibernate.show_sql=false
hibernate.jdbc.fetch_size=100
hibernate.jdbc.batch_size=100
hibernate.jdbc.batch_versioned_data=true
hibernate.order_inserts=true
hibernate.order_updates=true
hibernate.cache.use_query_cache=false
hibernate.cache.use_second_level_cache=false
</value>
</property>
</bean>
<!-- provides properties to hibernate to make it able to create session
factory. Hibernate uses instance of session bean of type -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<!-- responsible for creating sessionFactory opening transactions and binding
them to the current thread context. -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
<property name="nestedTransactionAllowed" value="true" />
</bean>
<!-- get exception translation from HibernateException into DataAccessException
hierarchy -->
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
but when trying to run the application, i got the following exception:
java.lang.ClassNotFoundException: org.hibernate.engine.SessionFactoryImplementor
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
please advise why i get this error, and how to fix it, thanks.
Try using the org.springframework.orm.hibernate4.HibernateTransactionManager
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="dataSource" ref="dataSource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>

Spring resource

Problem: I want to make the below bean definitions (specified in aaplicationContext.xml) optional for "org.springframework.web.context.ContextLoaderListener". If i am not providing the "emsPropLocation" context parameter correctly, tomcat web container is not able to initialized properly and it is obvious reason. Is there any way to make it optional?
appicationContext.xml:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="false"/>
<property name="location" value="file:/#{contextParameters.emsPropLocation}" />
</bean>
<!-- TIBCO Connection Factory Bean -->
<bean id="tibcoConnectionFactory" class="com.tibco.tibjms.TibjmsConnectionFactory">
<constructor-arg value="${emsServerURL}"/>
<property name="userName" value="${emsUserName}"/>
<property name="userPassword" value="${emsPassword}"/>
<property name="connAttemptCount" value="${connAttemptCount}"/>
<property name="connAttemptDelay" value="${connAttemptDelay}"/>
<property name="connAttemptTimeout" value="${connAttemptTimeout}"/>
<property name="reconnAttemptCount" value="${reconnAttemptCount}"/>
<property name="reconnAttemptDelay" value="${reconnAttemptDelay}"/>
<property name="reconnAttemptTimeout" value="${reconnAttemptTimeout}"/>
</bean>
<!-- bean id="tibcoUtil" class="com.nr.ns.upload.TibcoUtil" scope="singleton">
<constructor-arg value="true"/>
</bean-->
<bean id="jmsExceptionListener" class="com.nr.ns.upload.LogMsgExceptionListener"/>
<!-- Spring CachingConnectionFactory Bean -->
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<constructor-arg ref="tibcoConnectionFactory"/>
<property name="reconnectOnException" value="${reconnectOnException}"/>
<property name="sessionCacheSize" value="${sessionCacheSize}"/>
<property name="exceptionListener" ref="jmsExceptionListener"/>
</bean>
<!-- JMSTemplate Bean -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<constructor-arg ref="connectionFactory"/>
<property name="receiveTimeout" value="${receiveTimeout}"/>
<property name="deliveryMode" value="${deliveryMode}"/>
</bean>
We are keeping WAR file outside tomcat and to make it happen we have "app.xml" file inside TOMCAT_HOME/conf/Catalina/localhost.
app.xml:
<Context path="/app"
docBase="/abc/ccp/app.war"
reloadable="true"
unpackWAR="false">
<Parameter name="emsPropLocation"
value="/xyz/config/EMSServerConf.properties"
override="false"/>
</Context>
have a try to change the ignoreResourceNotFound property of your propertyConfigurer to true.
If contextParameters.emsPropLocation is not set, this will default to what is afer the colon.
<property name="location" value="file:/#{contextParameters.emsPropLocation:/xyz/config/EMSServerConf.properties}" />

Resources