Fail to create bean in spring suddently - java

I have encountered a problem of failed to create bean in spring suddenly. The webapp is already deployed and has been running for several months. However, below error message comes suddenly. It can be resolved by restarting the webapp, but comes again without any hints. Does anyone have any idea of this case?
Tomcat 6 is being used to host the webapp.
[2013/05/03 12:02:56:421 HKT] ajp-8009-42 org.ajax4jsf.webapp.BaseXMLFilter(227) - Exception in the filter chain
javax.servlet.ServletException: Error creating bean with name 'reportGenerationBean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'scheduleBean' while setting bean property 'scheduleBean'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduleBean': Invocation of init method failed; nested exception is java.lang.ArrayIndexOutOfBoundsException
applicationContext.xml as below
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:property-placeholder location="classpath*:webapp.properties,classpath*:env_prod.properties"/>
<context:annotation-config />
<bean id="facesUtils" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod">
<value>com.webapp.util.FacesUtils.init</value>
</property>
<property name="arguments">
<list>
<value>com.webapp.config.SpringBeanEnum</value>
<value>com.webapp.config.FacesBeanEnum</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref local="inspectbookSessionFactory"/></property>
</bean>
<context:component-scan base-package="com.webapp.bo, com.webapp.service" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="hibernateDAO" abstract="true">
<property name="sessionFactory"><ref local="inspectbookSessionFactory"/></property>
</bean>
<!-- Temporary Setting -->
<bean id="ItemSearchBeanDao" class="com.webapp.dao.tmp.ItemSearchBeanDao" parent="hibernateDAO">
<property name="maxRecordNo" value="${no_of_record.order}"/>
</bean>
<bean id="BookedSearchBeanDao" class="com.webapp.dao.tmp.BookedSearchBeanDao" parent="hibernateDAO">
<property name="maxRecordNo" value="${no_of_record.booked}"/>
</bean>
<bean id="ScheduleBeanDao" class="com.webapp.dao.tmp.ScheduleBeanDao" parent="hibernateDAO"></bean>
<bean id="WhItemSearchBeanDao" class="com.webapp.dao.tmp.WhItemSearchBeanDao" parent="hibernateDAO">
<property name="maxRecordNo" value="${no_of_record.whItem}"/>
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="-secret-"/>
</bean>
<bean id="EmailUtil" class="com.webapp.util.EmailUtil">
<property name="mailSender" ref="mailSender"/>
</bean>
<bean id="freeMarkerTemplateMailer" class="com.webapp.bo.email.impl.FreeMarkerTemplateMailer">
<property name="mailSender" ref="mailSender"/>
</bean>
<bean id="emailService" class="com.webapp.bo.email.impl.EmailServiceImpl" >
<property name="orgunitDao" ref="OrgunitDAO"/>
<property name="contactMethodDao" ref="ContactMethodDAO"/>
<property name="mailer" ref="freeMarkerTemplateMailer"/>
</bean>
<bean id="scheduleEmail" class="com.webapp.bo.schedule.impl.ScheduleEmailImpl" >
<property name="orgunitDao" ref="OrgunitDAO"/>
<property name="scheduleBeanDao" ref="ScheduleBeanDao"/>
<property name="emailService" ref="emailService"/>
</bean>
<bean name="scheduleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.webapp.service.schedule.ScheduleJob" />
<property name="jobDataAsMap">
<map>
<entry key="scheduleEmail" value-ref="scheduleEmail" />
</map>
</property>
</bean>
<!-- JSF backing bean START -->
<bean id="vendorSearchBean" class="com.webapp.service.search.item.VendorSearchBean" scope="session">
<property name="maxRecordNo" value="${no_of_record.vendor}"/>
</bean>
<bean id="itemSearchBean" name="itemSearchBean" class="com.webapp.service.search.item.NewItemSearchBean" scope="session">
<property name="maxRecordNo" value="${no_of_record.order}"/>
<property name="popupBean" ref="popupBean"/>
</bean>
<bean id="itemSearchPopupBean" name="itemSearchPopupBean" class="com.webapp.service.search.item.NewItemSearchBean" scope="session">
<property name="maxRecordNo" value="${no_of_record.order}"/>
</bean>
<bean id="detailBean" class="com.webapp.service.detail.DetailBean" scope="session">
<property name="itemSearchBean" ref="itemSearchBean"/>
<property name="itemSearchPopupBean" ref="itemSearchPopupBean"/>
<property name="popupBean" ref="popupBean"/>
</bean>
<bean id="bookedSearchBean" class="com.webapp.service.search.booked.BookedSearchBean" scope="session">
<property name="maxRecordNo" value="${no_of_record.booked}"/>
</bean>
<bean id="scheduleConfirmBean" class="com.webapp.service.schedule.ScheduleConfirmBean" scope="session">
<property name="popupBean" ref="popupBean"/>
</bean>
<bean id="scheduleBean" class="com.webapp.service.search.schedule.ScheduleBean" scope="session">
<property name="popupBean" ref="popupBean"/>
</bean>
<bean id="dropBean" class="com.webapp.service.search.schedule.DropBean" scope="request">
<property name="scheduleBean" ref="scheduleBean"/>
</bean>
<bean id="inspectContactBean" class="com.webapp.service.detail.contact.InspectContactBean" scope="session">
<property name="detailBean" ref="detailBean"/>
</bean>
<bean id="inspectLocationBean" class="com.webapp.service.detail.contact.InspectLocationBean" scope="session">
<property name="detailBean" ref="detailBean"/>
</bean>
<bean id="whItemSearchBean" class="com.webapp.service.search.warehouse.WhItemSearchBean" scope="session">
<property name="maxRecordNo" value="${no_of_record.whItem}"/>
<!--<property name="propertiesUtil" ref="propertiesUtil"/>-->
</bean>
<!-- Autocomplete -->
<bean id="autocomplete" class="com.webapp.service.common.AutocompleteBean" scope="session"></bean>
<!-- PackingListBean -->
<bean id="packingListBean" class="com.webapp.service.common.PackingListBean" scope="session">
<property name="itemSearchBean" ref="itemSearchBean"/>
<property name="popupBean" ref="popupBean"/>
</bean>
<!-- Report Bean -->
<bean id="reportGenerationBean" class="com.webapp.service.report.ReportGenerationBean" scope="request">
<property name="itemSearchBean" ref="itemSearchBean"/>
<property name="packingListBean" ref="packingListBean"/>
<property name="scheduleBean" ref="scheduleBean"/>
</bean>
<!-- popupBean -->
<bean id="popupBean" class="com.webapp.service.common.PopupControlBean" scope="session">
</bean>
<!-- JSF backing bean END -->
</beans>

Related

What changes are required to use Hibernate along with IBatis and jdbc connection pooling

We want to integrate Hibernate 5 in our project, and complexity is that we are using IBatis with Spring 4
my persistence.xml looks like:
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/MYJNDI" />
<!-- SqlMap setup for iBATIS Database Layer -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:/sql-map-mysql.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven proxy-target-class="true" />
<!-- Generic Dao - can be used when doing standard CRUD -->
<bean id="baseDaoiBATIS" class="com.test.database.BaseDaoiBATIS">
<property name="dataSource" ref="dataSource" />
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath*:mybatis-resources/*.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sessionFactory" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.test.database.mapper" />
</bean>
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.hostname}"></property>
<property name="port" value="${redis.port}"></property>
<property name="usePool" value="true"></property>
</bean>
<bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"></bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"></property>
<property name="keySerializer" ref="stringRedisSerializer"></property>
<property name="hashKeySerializer" ref="stringRedisSerializer"></property>
</bean>
</beans>
What changes we should do to have Hibernate5 along with IBatis Any suggestions would be greatly appreciated
Note: We are using spring4,Ibatis ,Connection pooling
We made changes as per suggestion by #M.Deinum and it's working:
Approach we followed are:
[1] using Hibernate-3 with spring 3
[2] using Hibernate Transaction Manager instead of DataSourceTransactionManager :
<!-- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> -->
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.test.database.domain" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<bean id="persistenceExceptionTranslationPostProcessor" class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

How to create cache expiry policy in ignite server by xml?

This is my example-default.xml,
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
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.xsd">
<bean abstract="true" id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Set to true to enable distributed class loading for examples, default is false. -->
<property name="peerClassLoadingEnabled" value="true"/>
<!-- Enable task execution events for examples. -->
<property name="includeEventTypes">
<list>
<!--Task execution events-->
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED"/>
<!--Cache events-->
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/>
</list>
</property>
<property name="CacheExpiryPolicy">
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="expiryPolicyFactory">
<bean class="javax.cache.expiry.CreatedExpiryPolicy" factory-method="factoryOf">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="MINUTES"/>
<constructor-arg value="5"/>
</bean>
</constructor-arg>
</bean>
</property>
</bean>
</property>
But the above gives Bean property 'CacheExpiryPolicy' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
How I can solve this?
I found an apache-ignite-users forum question on this.
Please refer to this here
So, the final updated xml according to that forum reference is :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
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.xsd">
<!-- Added cache expiry policy -->
<bean id="cacheExpiryPolicy"
class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
<constructor-arg>
<bean class="javax.cache.expiry.CreatedExpiryPolicy">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="MINUTES" />
<constructor-arg value="5" />
</bean>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
<bean abstract="true" id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Set to true to enable distributed class loading for examples, default
is false. -->
<property name="peerClassLoadingEnabled" value="true" />
<!-- Enable task execution events for examples. -->
<property name="includeEventTypes">
<list>
<!--Task execution events -->
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED" />
<!--Cache events -->
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED" />
</list>
</property>
<!-- set the cacheConfiguration property -->
<property name="cacheConfiguration">
<list>
<bean
class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="default" />
<property name="atomicityMode" value="ATOMIC" />
<property name="expiryPolicyFactory">
<bean parent="cacheExpiryPolicy" />
</property>
</bean>
</list>
</property>
</bean>
</beans>
Here is the example from the documentation:
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="cacheWithExpiryPolicy"/>
<property name="expiryPolicyFactory">
<bean class="javax.cache.expiry.CreatedExpiryPolicy" factory-method="factoryOf">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="MINUTES"/>
<constructor-arg value="5"/>
</bean>
</constructor-arg>
</bean>
</property>
</bean>
</list>
</property>

Spring.xml error config

I have this error when run spring project by -cp
java -cp "parser.jar" hu.daniel.hari.learn.spring.orm.main.SpringOrmMain
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/p]
Offending resource: class path resource [spring.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:309)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateIfRequired(BeanDefinitionParserDelegate.java:1464)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1440)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1428)
My beans.xml
<?xml version="1.0" encoding="UTF-8"?>
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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
">
<!-- Scans the classpath for annotated components that will be auto-registered
as Spring beans -->
<context:component-scan base-package="hu.daniel.hari.learn.spring" />
<!-- Activates various annotations to be detected in bean classes e.g: #Autowired -->
<context:annotation-config />
<!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" /> <property
name="url" value="jdbc:hsqldb:mem://productDb" /> <property name="username"
value="sa" /> <property name="password" value="" /> </bean> -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/newparser" />
<property name="username" value="postgres" />
<property name="password" value="postgres" />
<!--<property name="socketTimeout" value="10"/> -->
<property name="connectionProperties">
<props>
<prop key="socketTimeout">10</prop>
</props>
</property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:packagesToScan="hu.daniel.hari.learn.spring.orm.model"
p:dataSource-ref="dataSource">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
<!-- Transactions -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Add namespace for the shorthand property (p:)
<beans
...
xmlns:p="http://www.springframework.org/schema/p"

How to fix No bean named 'springSecurityFilterChain' is defined

I'm developping a web application using spring, hibernate and primefaces.
In this application I get data from a database and use it to display charts.
when I run my application I get this error :
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
This is the application context file :
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.6.SEC01.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.6.SEC01.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.6.SEC01.xsd
">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/biblio?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value></value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="mappingResources">
<list>
<value>Mapping/Status.hbm.xml</value>
<value>Mapping/Authorities.hbm.xml</value>
<value>Mapping/Livre.hbm.xml</value>
<value>Mapping/Users.hbm.xml</value>
<value>Mapping/Auteur.hbm.xml</value>
<value>Mapping/Emprunteur.hbm.xml</value>
<value>Mapping/Collection.hbm.xml</value>
<value>Mapping/Emprunt.hbm.xml</value>
<value>Mapping/Cathegorie.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<!--Spring Data Access Exception Translator Defintion-->
<bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator" >
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<!--Hibernate Template Defintion-->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" >
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
<property name="jdbcExceptionTranslator">
<ref bean="jdbcExceptionTranslator"/>
</property>
</bean>
<!--Hibernate Transaction Manager Definition-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!--========================= Start of DAO BEANS DEFINITIONS =========================-->
<bean id="autDao" class="Implementation.dao.AuteurDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="statusDao" class="Implementation.dao.StatusDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="categDao" class="Implementation.dao.CategorieDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="empDao" class="Implementation.dao.EmprunteurDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="colleDao" class="Implementation.dao.CollectionDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="livDao" class="Implementation.dao.LivreDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="emprDao" class="Implementation.dao.EmpruntDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<!--========================= Start of SERVICE BEANS DEFINITIONS =========================-->
<bean id="auDao" class="Implementation.service.AuteurServiceImpl" >
<property name="auteurDao" ref="autDao"/>
</bean>
<bean id="statDao" class="Implementation.service.StatusServiceImpl" >
<property name="statusDao" ref="statusDao"/>
</bean>
<bean id="catDao" class="Implementation.service.CategorieServiceImpl" >
<property name="categorieDao" ref="categDao"/>
</bean>
<bean id="emprunDao" class="Implementation.service.EmprunteurServiceImpl" >
<property name="emprunteurDao" ref="empDao"/>
</bean>
<bean id="collectionDao" class="Implementation.service.CollectionServiceImpl" >
<property name="collectionDao" ref="colleDao"/>
</bean>
<bean id="livrDao" class="Implementation.service.LivreServiceImpl" >
<property name="livreDao" ref="livDao"/>
</bean>
<bean id="empruDao" class="Implementation.service.EmpruntServiceImpl" >
<property name="empruntDao" ref="emprDao"/>
</bean>
</beans>
How can I solve this problem ?
Looks like you are using spring security filter in your application.
Can you post your web.xml?
You have to define in you web.xml
filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Spring Hibernate Database Connections

I am in the process of learning Hibernate, Spring and JPA.
I would like to know whether my database connections are closed automatically by Spring or not. When I looked at database table v$session I can find there are four JDBC Thin Client
sessions. So would like to know whether these connections are from my application.
Below is my applicationContext.xml. Any help is highly appreciable.
<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: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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
>
<context:component-scan base-package="net.test" />
<!-- Data Source Declaration -->
<bean id="DataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myDS"/>
</bean>
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean class="org.springframework.orm.hibernate4.HibernateExceptionTranslator" />
<!-- JPA Entity Manager Factory -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="DataSource" />
<property name="packagesToScan" value="net.test.entity" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="${jdbc.dialectClass}" />
</bean>
</property>
</bean>
<bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" />
<!-- Session Factory Declaration -->
<bean id="SessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="DataSource" />
<property name="annotatedClasses">
<list>
<value>net.test.entity.Employee</value>
<value>net.test.entity.Department</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory
</prop>
</props>
</property>
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="SessionFactory" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- <tx:annotation-driven transaction-manager="txManager"/> -->
<context:annotation-config />
<bean id="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService">
<property name="statisticsEnabled" value="true" />
<property name="sessionFactory" value="#{entityManagerFactory.sessionFactory}" />
</bean>
<bean name="ehCacheManagerMBean"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"
lazy-init="false">
<property name="server" ref="mbeanServer" />
<property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING" />
<property name="beans">
<map>
<entry key="SpringBeans:name=hibernateStatisticsMBean"
value-ref="hibernateStatisticsMBean" />
<entry key="SpringBeans:name=ehCacheManagerMBean" value-ref="ehCacheManagerMBean" />
</map>
</property>
</bean>
</beans>
Spring closes connections when the transaction is committed of rollbacked. But the connections are pooled connections, so closing them simply puts them back into the pool of connections, and doen't physically closes them.
The first goal is to be able to get a new connection from the pool extremely quickly, without having to recreate a new physical connection each time, because it's a costly operation.
The other goal is to be able to put a limit on the number of opened connections, to avoid bringing the database to its knees.
Note that the pool of connections, in your case, isn't handled by Spring, but by your application server, which makes it available from JNDI.

Categories

Resources