Spring #Transaction not rolling back on RuntimeException - spring

I want to support rollback when an exception occurs in my code.
I use junit + datasource in Spring config file for testing and Glassfish 2.1 for the real code (using jndi datasource).
Here a sample of the code.
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "classpath:test-web-spring-config.xml" })
public class PersistTest {
#Autowired
Transformer transformer;
#Before
public void setUp() throws Exception {
}
#After
public void tearDown() throws Exception {
}
#Test
#Transactional("transactionManagerTest")
//#Rollback(false)
// #Ignore
public void test() {
transformer.export();
}
}
#Component
public class Transformer {
#Autowired
ContextPersist context;
#Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
public void export(){
//code here
// persist here
context.persist();
// to test a rollback
throw new RuntimeException("testing rollback2");
}
}
#Component
public class ContextPersist {
#Autowired
#Qualifier(value = "dataSource")
DataSource dataSource;
// bulk insert
JdbcTemplate jdbcTemplate;
#Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
public void persist() {
jdbcTemplate = new JdbcTemplate(dataSource);
//.. here I insert data with jdbcTemplate.batchUpdate(....)
// to test a rollback
throw new RuntimeException("testing rollback1");
}
}
That code doesn't rollback.
If I use #Rollback(true) in my Junit, the transaction will rollback. But I need the same behavior outside a JUnit.
EDITED : (added the spring config)
My project contains a webapp (demo.war) and a jar for DAO+businessrules
In my webapp, I have my transformer.
I have a parent Spring config in this webapp, and a common spring config shared with others webapps.
Here the files.
demo.war
web-spring-config.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<context:component-scan base-package="com.test" />
<tx:annotation-driven />
<task:annotation-driven/>
<import resource="classpath:common-spring-config.xml" />
</beans>
DAO.jar
common-spring-config.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<context:component-scan base-package="com.test" />
<tx:annotation-driven />
<task:annotation-driven/>
<!-- Hibernate -->
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="demo.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.show_sql">false</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<!-- datasource -->
<bean id="demo.datasource" class="org.springframework.jndi.JndiObjectFactoryBean"
lazy-init="true">
<property name="jndiName" value="jdbc/demo" />
</bean>
</beans>

your transaction manager is
org.springframework.orm.hibernate3.HibernateTransactionManager
but you use JdbcTemplate
the AOP is configured to auto begin/commit/rollback on hibernate operations.
jdbcTemplate would not participate in any transaction.
no transaction = no rollback.
its like connection.setAutoCommit(true);

Related

autowiring spring bean in camel processor

I am building OSGI bundle for running in Jboss Fuse 6.1 container. Project contains blueprint.xml (in src/main/resoureces/OSGI-INF/blueprint). It is content:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd"
>
<bean id="MyProcessor" class="com.test.MyProcessor" />
<camelContext trace="false" id="blueprintContext" xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="activemq:queue:paymentsqueue?username=admin&password=admin" id="NotificationRoute">
<description/>
</from>
<log message="The message contains ${body}"/>
<process ref="MyProcessor"/>
</route>
</camelContext>
</blueprint>
My goal is using spring beans in MyProcessor. This is code for MyProcessor:
public class MyProcessor implements Processor {
#Aurowired
private Sender sender;
#Override
public void process(Exchange x) throws Exception {
log.info("test: " +sender.getSenderId());
}
}
But it gives me nullpointerexception. What I am doing wrong?
This is content of my spring configuration file(i placed it in src/main/resoureces/META-INF/spring)
<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: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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.username"/>
<bean id="sender" class="com.username.Sender" scope="prototype">
<property name="senderId" value="sendername" />
<property name="password" value="senderpassword" />
</bean>
I think you have not declared the Processor MyProcessor as a bean in spring like
<bean id="myProcessor"
class="com.test.MyProcessor" />
then you can use it as
<process ref="myProcessor"/>
Also the
#Aurowired
private Sender sender;
should be #Autowired(This should be a typo but pointed it out.)

Spring AOP - expression "&&" Not working while combining pointcuts

Aspect Class:
#Aspect
public class LoggingAspect {
#Before("e1() && e2()")
public void loggingAdvice(){
System.out.println("before execution of the method");
}
#Pointcut("execution(public String com.spring.Employee.getName())")
public void e1(){}
#Pointcut("execution(public String com.spring.Department.getName())")
public void e2(){}
}
Client Class:
public class AspectClient {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Employee emp = (Employee) context.getBean("employee");
System.out.println(emp.getEmpId());
System.out.println(emp.getName());
System.out.println(emp.getDepartment().getName());
}
**Config 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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
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 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id= "employee" class="com.spring.Employee" autowire="byName">
<property name="empId" value="7329" />
<property name="name" value="Sagar" />
</bean>
<bean id= "department" class="com.spring.Department" >
<property name="name" value="ApplicationManagement" />
<property name="typeOfProjects" value="Maintenance" />
</bean>
<bean class="com.spring.LoggingAspect"/>
<aop:aspectj-autoproxy />
<context:annotation-config />
</beans>
Explanation:
#Before("e1() && e2()")
When I just call either e1() or e2() individually, it works but not both at same time.
I dont get any errors., Just the advices are not called.
I am using spring 3.2.3
AspectJ and AOP alliance jar files
Which is as expected. The pointcut never matches it will never match both the execution e1 and execution e2 on the same time. Instead of && you probably want || .
It basically is an if statement and both sides have to resolve to true a

Cannot Apply AOP in Glassfish

Hi need help in learniing basic spring .
i have a simple Aspect
#Aspect
public class HelloAspect {
static final Logger log = Logger.getLogger(HelloAspect.class .getClass().getName());
#Before("execution(* *.*(..))")
public void logBefore(JoinPoint joinPoint) {
log.info("The method " + joinPoint.getSignature().getName()+ "() begins with "+Arrays.toString(joinPoint.getArgs()));
}}
dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<aop:aspectj-autoproxy />
<context:component-scan base-package="com"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<context:annotation-config></context:annotation-config>
<context:load-time-weaver/>
<bean class="com.abhi.aop.HelloAspect"/>
<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
</beans>
application-context.xml is
I have a simple entity from derby table and controller mapping
goal is to print logbefore logger before every method.
but i get nothing on server after deployment log.

Could I use Spring EL inside bean id attribute?

Could I use SpEL inside the id attribute of a bean ?
e.g :
<bean id="#{T(com.om.m).PublicStaticFinalStringProperty}"...
This way it's not working, what should I change or it's not possible ?
Weird but possible (sample uses spring 3.1). Different versions working:
<?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"
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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
">
<context:property-placeholder properties-ref="myProps"/>
<util:properties id="myProps" >
<prop key="x.y.z">possible</prop>
</util:properties>
<bean id="testBean" class="Bean">
<property name="value" value="weird"/>
</bean>
<bean id="${x.y.z}" class="Bean">
<property name="value" value="but"/>
</bean>
<bean id="#{testBean.value}" class="Bean">
<property name="value" value="${x.y.z}"/>
</bean>
</beans>
Bean.java
public class Bean implements InitializingBean {
String value;
public void setValue(String value) {
this.value = value;
}
public void afterPropertiesSet() throws Exception {
System.out.println(value);
}
}

The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'

I am trying to configure JSF+Spring+hibernate and I'm tying to run a test but when I use this "tx:annotation-driven" on my application-context.xml file, I get this error:
The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'
Here is my application-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:aop="http://www.springframework.org/schema/aop"
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-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.6.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.6.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.6.xsd
" xmlns:tool="http://www.springframework.org/schema/tool">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#192.168.56.101:1521:Gpsi"/>
<property name="username" value="omar"/>
<property name="password" value="omar"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>om.mycompany.model.Course</value>
<value>om.mycompany.model.Student</value>
<value>om.mycompany.model.Teacher</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction.manager="transactionManager"/>
<context:annotation-config/>
<context:component-scan base.package="com.mmycompany"/>
</beans>
and here is my CourseServiceImplTest. I have still not implemented the tests:
public class CourseServiceImplTest {
private static ClassPathXmlApplicationContext context;
private static CourseService courseService;
public CourseServiceImplTest() {
}
#BeforeClass
public static void setUpClass() throws Exception {
context=new ClassPathXmlApplicationContext("application-context.xml");
courseService=(CourseService) context.getBean("courseService");
}
#AfterClass
public static void tearDownClass() throws Exception {
context.close();
}
#Before
public void setUp() {
}
#After
public void tearDown() {
}
/**
* Test of getAllCourses method, of class CourseServiceImpl.
*/
#Test
public void testGetAllCourses() {
System.out.println("getAllCourses");
CourseServiceImpl instance = new CourseServiceImpl();
List expResult = null;
List result = instance.getAllCourses();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of getCourse method, of class CourseServiceImpl.
*/
#Test
public void testGetCourse() {
System.out.println("getCourse");
Integer id = null;
CourseServiceImpl instance = new CourseServiceImpl();
Course expResult = null;
Course result = instance.getCourse(id);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
and here is the CourseServiceImpl:
#Service("courseService")
#Transactional
public class CourseServiceImpl implements CourseService{
#Autowired
private SessionFactory sessionFactory;
#Override
public List<Course> getAllCourses() {
return sessionFactory.getCurrentSession().createQuery("from Course").list();
}
#Override
public Course getCourse(Integer id) {
return (Course) sessionFactory.getCurrentSession().get(Course.class, id);
}
#Override
public void save(Course course) {
sessionFactory.getCurrentSession().saveOrUpdate(course);
}
}
You have some errors in your appcontext.xml:
Use *-2.5.xsd
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.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"
Typos in tx:annotation-driven and context:component-scan (. instead of -)
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan base-package="com.mmycompany" />
This is for others (like me :) ). Don't forget to add the spring tx jar/maven dependency.
Also correct configuration in appctx is:
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
, by mistake wrong configuration which others may have
xmlns:tx="http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
i.e., extra "/spring-tx-3.1.xsd"
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
in other words what is there in xmlns(namespace) should have proper mapping in
schemaLocation (namespace vs schema).
namespace here is : http://www.springframework.org/schema/tx
schema Doc Of namespace is : http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
this schema of namespace later is mapped in jar to locate the path of actual xsd located in org.springframework.transaction.config
For me the thing that worked was the order in which the namespaces were defined in the xsi:schemaLocation tag : [ since the version was all good and also it was transaction-manager already ]
The error was with :
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
AND RESOLVED WITH :
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
I'm learning from udemy. I followed every step that my instructor show me to do.
In spring mvc crud section while setting up the devlopment environment i had the same error for:
<mvc:annotation-driven/> and <tx:annotation-driven transaction-manager="myTransactionManager" />
then i just replaced
http://www.springframework.org/schema/mvc/spring-mvc.xsd
with
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
and
http://www.springframework.org/schema/tx/spring-tx.xsd
with
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
actually i visited these two sites
http://www.springframework.org/schema/mvc/ and http://www.springframework.org/schema/tx/
and just added the latest version of spring-mvc and spring-tx i.e, spring-mvc-4.2.xsd and spring-tx-4.2.xsd
So, i suggest to try this.
Hope this helps.
Thank you.
One extra forward slash (/) in front of tx and the *.xml file troubled me for 8 hours!!
My mistake:
http://www.springframework.org/schema/tx/ http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
Correction:
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
Indeed one character less/more manages to keep programmers busy for hours!
In my case this was actually a symptom of the server, hosted on AWS, lacking an IP for the external network. It would attempt to download namespaces from springframework.org and fail to make a connection.
FWIW I had this same issue. Turned out my xsi:schemaLocation entries were incorrect, so I went to the official docs and pasted theirs into mine:
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html section 16.5.6
I had to add a couple more but that was ok. Next up is to find out why this fixed the problem...
Make sure that Spring version and xsd version both are same.In my case I am using Spring 4.1.1 so my all xsd should be version *-4.1.xsd
Any one can help for me!!!!!!!!!
<?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:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop/ http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context/ http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee/ http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang/ http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx/ http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util/ http://www.springframework.org/schema/util/spring-util.xsd">
<context:annotation-config />(ERROR OCCUR)
<context:component-scan base-package="hiberrSpring" /> (ERROR OCCUR)
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages"></property>
<property name="defaultEncoding" value="UTF-8"></property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties"></bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${com.mysql.jdbc.Driver}"
p:url="${jdbc:mysql://localhost/}" p:username="${root}"
p:password="${rajini}"></bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<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="employeeDAO" class="hiberrSpring.EmployeeDaoImpl"></bean>
<bean id="employeeManager" class="hiberrSpring.EmployeeManagerImpl"></bean>
<tx:annotation-driven /> (ERROR OCCUR)
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>

Resources