I'm trying to connect dtatbase to my web application. Database in MSSQL server. Here is my applicationContext.xml 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: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-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<bean id="txManagerDH" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="dhSessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManagerDH"/>
<bean id="dhDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
p:url="jdbc:sqlserver://TARAS-PC\SQLEXPRESS:1433:databaseName=DH:"
p:username="GlassfishDH"
p:password="glassfish" />
<bean id="dhSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
p:dataSource-ref="dhDataSource">
<property name="annotatedClasses">
<list>
<value>model.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<bean id="UserDao" class="model.UserDao" p:sessionFactory-ref="dhSessionFactory"/>
<bean id="UserService" class="service.UserService"
p:userDao-ref="UserDao"/>
</beans>
When I'm trying run it I have an error:
Error occurred during deployment: 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 'txManagerDH' defined in ServletContext
resource [/WEB-INF/applicationContext.xml]: BeanPostProcessor before
instantiation of bean failed; nested exception is
java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice. Please see
server.log for more details.
I don't what is wrong in my code. Please help me.
You're missing the aop-alliance library from your class path. You can get the binary or the maven dependency here.
Alternatively, get the full spring-aop library.
If your facing the same problem, then you miss aopalliance.jar. Here in this location you can the load the jar http://mvnrepository.com/artifact/aopalliance/aopalliance/1.0. Also it is recommend that you use Maven to handle all these dependencies instead of doing it yourself. I faced the same issue here it is solved. Here my post : Not able to load the applicationContext.xml in Spring. If this problem is solved there would be another in compatability of spring 4.0.0 with hibernate 4.30.
In dipatcher-servlet,instead of
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
Use
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
Related
I am trying to configure Spring 4 with Hibernate 5.Made a google research but it didn't help. I am launching my app with JUnit test, just to see if Hibernate works.
Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in class path resource [ConfigTest/datasource.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.<init>(Lorg/hibernate/boot/MetadataSources;)V; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [ConfigTest/datasource.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.<init>(Lorg/hibernate/boot/MetadataSources;)V
This is my datasource.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
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-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<context:component-scan base-package="/WebMVCtest/test/Config">
</context:component-scan>
<beans profile="dev">
<context:property-placeholder
location="ConfigTest/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="username" value="${jdbc.username}"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>DAO</value>
</list>
</property>
</bean>
</beans>
</beans>
Also When I use Hibernate 4 I face an error :
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'offersDao': Injection of autowired dependencies failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cache/spi/RegionFactory
but I do have RegionFactory at that address:
enter image description here
Thanful in advance!
It appears that the packagesToScan property wants an array.
In your case, I suppose it would look like this...
<property name="packagesToScan">
<array>
<value>DAO</value>
</array>
</property>
Or maybe simply...
<property name="packagesToScan" value="DAO" />
The problem was in compatability of versions. So I used Spring 4.0.3.RELEASE and Hibernate 4.3.5.Final and the error is gone.
Also I had an error : no current session found. So I've refractored a little a transaction bean :
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<tx:annotation-driven />
Beating my head against the wall for hours and can't resolve this issue, seems to be either a mistake in my config setup or maybe a dependency conflict or missing dependency. Any thoughts?
Relevant dependencies:
Spring Data Commons Core 1.2.0
Spring Data JPA 1.8.0
Hibernate Core 5.0
Hibernate JPA 2.1
Error message in Eclipse:
Configuration problem: Failed to import bean definitions from relative location [SpringDbContext.xml] Offending resource: class path resource [SpringAppContext.xml]; nested exception is
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 43 in XML document from class path resource [SpringDbContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; systemId:
http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd; lineNumber: 43; columnNumber: 63; src-resolve: Cannot resolve the name 'repository:auditing-attributes' to a(n) 'attribute group' component.at
org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
SpringAppContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<import resource="SpringWebContext.xml"/>
<import resource="SpringDbContext.xml"/>
<import resource="SpringSecurityContext.xml"/>
<import resource="SpringSocialContext.xml"/>
<context:component-scan base-package="com.metagravy.ark.security"/>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="i18n/messages"/>
<property name="useCodeAsDefaultMessage" value="true"/>
</bean>
</beans>
Hibernate configs:
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.format_sql=true
hibernate.hbm2ddl.auto=create-drop
hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
hibernate.show_sql=false
SpringDbContext.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:jpa="http://www.springframework.org/schema/data/jpa"
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-4.1.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<context:property-placeholder location="classpath:application.properties"/>
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource">
<property name="driverClass" value="${db.driver}"/>
<property name="jdbcUrl" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven/>
<bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
<property name="packagesToScan" value="com.metagravy.ark"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.ejb.naming_strategy">${hibernate.ejb.naming_strategy}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
<jpa:repositories base-package="com.metagravy.ark.security"/>
</beans>
Thanks for the help, I upgraded spring-data-commons from 1.2 to 1.10 and it resolved the error.
I'm developing a simple standalone Java application using Spring and Hibernate to try to learn them.
I'm having some problems in the configuration of Spring and Hibernate, in order to really create some "useful" result from the code...
I've tried to follow the examples as reported in the book "Beginning Hibernate 2nd edition" and "Pro Spring 3", but i'm having , regarding Hibernate, this problem (i'm using log4j for the logging) :
1824 [main] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#38638273: defining beans [dataSource,sessionFactory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,personaDao,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [app-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [${jdbc.driverClassName}]
It seems that the placeholder is ignored in the parsing of the configuration files
Here i've have copied an extract of them :
app-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" >
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven/>
<bean id="personaDao" class="org.bladela.dataaccess.persona.PersonaDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<mapping class="org.bladela.dataaccess.persona.Persona"/>
</session-factory>
</hibernate-configuration>
jdbc.properties :
jdbc.driverClassName=org.postgresql.Driver
jdbc.dialect=org.hibernate.dialect.PostgreSQLDialect
jdbc.databaseurl=jdbc:postgresql://localhost:5432/employeemanagementdb
jdbc.username=bladela
jdbc.password=password
if i substitute all the placeholders with their values, the program goes on and it connects to the db (if i substitute only one...the error "goes" to the next one)
then it return an incorrect result (an empty list when it should return a list with one element) but maybe i'll ask about it later, if i can't solve it.
Any suggestion?
I don't see any PropertyPlaceholderConfigurer declared in your context. How are property placeholders supposed to be resolved?
One solution is to add
<context:property-placeholder location="classpath:jdbc.properties"/>
to your context.
I have a Spring Batch application that has a Spring context configuration that normally each batch job would reference. This way each batch job uses the same entity manager.
batch-context.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- ... -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="myPersistenceUnit" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="packagesToScan" value="com.example.domain" />
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">100</prop>
<prop key="hibernate.jbc.batch_size">1000</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_sql_comments">false</prop>
</props>
</property>
</bean>
<!-- ... -->
</beans>
Now in my specific batch job context (call it ExampleBatch.xml) I want to add another package to scan to the already defined entityManagerFactory bean. Is this possible?
ExampleBatch.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<!-- ... -->
<import resource="classpath:batch-context.xml" />
<bean id="entityManagerFactoryWithExtraPackages"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
parent="entityManagerFactory">
<!-- How do I override the packagesToScan property on the already defined entityManagerFactory bean?-->
<property
name="packagesToScan"
value ="com.example.domain,com.example.domain.abstraction"
/>
</bean>
<!-- ... -->
</beans>
The way I have it right now will not work because it complains that "No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2"
Is trying to override the "packagesToScan" property the right approach to take in this scenario? Is there a better way to accomplish this behavior?
Edit:
I was able to accomplish what I needed using the property-override functionality. Below is the updated ExampleBatch.xml that I went with
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:util="http://www.springframework.org/schema/util"
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/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<!-- ... -->
<import resource="classpath:batch-context.xml" />
<context:property-override properties-ref="entityManagerOverride"/>
<bean id="entityManagerOverride"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<util:properties>
<prop key="entityManagerFactory.packagesToScan">com.example.domain,com.example.batch.module.domain</prop>
</util:properties>
</property>
</bean>
<!-- ... -->
</beans>
So far Spring does not yell at me that this is an invalid configuration. Have yet to determine if this is in fact producing the desired outcome.
Edit 2:
The property-override method does not appear to be sufficient. It is a valid configuration but after inspecting the entity manager at runtime like this:
for (EntityType<?> entity : manager.getMetamodel().getEntities()) {
String name = entity.getName();
System.out.println(name);
}
It only contains entities from the com.example.domain package.
Does anyone have any other ideas?
The way you have it now, you really define two separate beans - one called entityManagerFactory and the other one entityManagerFactoryWithExtraPackages.
There are several ways to solve your very request:
Just get rid of one of the beans - merge the definitions into one.
I only guess it's not an option for you, otherwise you wouldn't ask.
Define the entityManagerFactory as abstract, then you end up having one bean anyway.
Use the property override mechanism. This fits the scenarios, where you are not in control of the 'top' bean and despite that you want to re-configure (literally override the values of the properties of) beans defined there.
Just replace this:
<property
name="packagesToScan"
value ="com.example.domain,com.example.domain.abstraction"/>
with this:
<property name="packagesToScan">
<array>
<value>com.example.domain</value>
<value>com.example.domain.abstraction</value>
</array>
</property>
If it fits your packages organization, you may try
<property name="packagesToScan" value="com.example.domain.*" />
In your batch-context.xml, so your ExampleBatch.xml doesn't have anymore to "override" the parent.
Another way to dig is using placeholder; in batch-context.xml, you would use :
<property name="packagesToScan" value="${packageList}" />
while in ExampleBatch.xml you would declare the placeholder with the appropriate value, as explained for example here : http://www.mkyong.com/spring/spring-propertyplaceholderconfigurer-example/
I'm trying to use Hibernate in my Spring application but i've got an error on the project's deployment
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/dispatcher-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class' for property 'configurationClass'; nested exception is java.lang.IllegalArgumentException: Cannot find class [org.hibernate.cfg.AnnotationConfiguration].
Here my dispatcher-servlet with the bean session factory :
<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: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"
default-autowire="byName">
<context:component-scan base-package="hibernateTest" />
<context:annotation-config/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
And my hibernate-cfg.xml :
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping class="hibernateTest.web.InventoryController" />
</session-factory>
</hibernate-configuration>
I've many jars in my classpath and i thoutgh it doesn't miss anyone. Could you help me finding an issue ?
Thanks
You need to put the hibernate-annotations.jar on the classpath.
Cannot find class [org.hibernate.cfg.AnnotationConfiguration]
This is the reason, Can you check for this class in classpath.
org.hibernate.cfg.AnnotationConfiguration is deprecated,
and all its functionality has been moved to org.hibernate.cfg.Configuration.
change your code
<property name="configurationClass">
<value>org.hibernate.cfg.Configuration</value>
</property>