Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6680609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:29:40+00:00 2026-05-26T04:29:40+00:00

So my Spring education continues. Currently I’m trying to learn some of the annotations

  • 0

So my Spring education continues. Currently I’m trying to learn some of the annotations and the things they bring to Spring 3. So I’ve got a mini webapp that can connect to a DB and put stuff in through a form and display records and so on. Everything works fine. I decided to try and get Spring to auto-detect the service bean that I have marked as @Transactional but doing that stops the app from saving to the DB. So:

@Transactional
public class ReservationServiceImpl implements ReservationService {

that works. I have a bean declaration of this class in my springcourt-data.xml files. No problems. When I do this though:

@Transacational
@Service("reservationService")
public class ReservationServiceImpl implements ReservationService {

it no longer works. And I do have

<context:component-scan base-package="com.springcourt" />

in the springcourt-servlet.xml file. So can anyone tell me what I’m screwing up? All I do is add another annotation to this class and remove the bean definition from the xml file and it no longer saves data to the DB. I can still query records and stuff from the DB though so obviously it’s using the autodetected service bean.

Here are the config files:

springcourt-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<context:component-scan base-package="com.springcourt" />

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="webBindingInitializer">
        <bean class="com.springcourt.web.ReservationBindingInitializer" />
    </property>
</bean>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>
</beans>

And:

springcourt-data.xml
<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:p="http://www.springframework.org/schema/p"
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-2.0.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
        <bean
            class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database" value="MYSQL" />
            <property name="showSql" value="true" />
        </bean>
    </property>
</bean>

<bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/test" />
    <property name="username" value="root" />
    <property name="password" value="admin" />
    <property name="initialSize" value="5" />
</bean>

<bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven />

<bean id="reservationService" class="com.springcourt.service.ReservationServiceImpl"/>
</beans>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:29:43+00:00Added an answer on May 26, 2026 at 4:29 am

    When you use @Service and component scanning the bean is created by the context created by the dispatcher servlet (mvc). Since the transaction:annotation driven is defined in the root application context it doesn’t apply to the beans in the servlets context. You can verify this by removing the @Service and moving the bean definition to the servlet context file – you should see the same result.

    Where as when you don’t use component scanning – the bean is defined in the XML of the root application context.

    The fix is to change the component-scan tag in the web layer to only include web layer classes – either by using a different base package or by using an include / exclude filter. Add another component scan in the root application context for the other beans.

    Querying might be working because you might have a OpenEntityManagerInViewInterceptor / Filter configured.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

long time ASP.Net interface developer being asked to learn WCF, looking for some education
Spring support JUnit quite well on that: With the RunWith and ContextConfiguration annotation, things
Spring 3.1 Tomcat 6.* I'm working on making a Spring 3.1 webapp, authenticating with
In Spring MVC Hibernate application , when i am trying to use properties file
Okay, so I've noticed, going through some programs other people have written (for education
I'm using VS 2012RC and I write some simple C# methods for education purposes.
Like some of you allready know, i'm trying to get data from facebook in
Spring MVC uses a DispatcherServlet to route control to an appropriate Controller. But where
Spring supports programmatic transaction which give us fine grained control over TX management. According
Spring Framework provides many technologies for applications to communicate with each other over HTTP.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.