Announcement Announcement Module
Collapse
No announcement yet.
service class not being autoproxied Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • service class not being autoproxied

    I have a service class called ProjectManagerImp that implements the ProjectManager Interface.

    An instance of ProjectManagerImp is injected into ProjectController

    Code:
    public class ProjectController extends SimpleFormController {
    
           [...]	
    
    	private ProjectManager projectManager;
    
           [...]
    projectManager has a public no-arg constructor.

    ProjectController calls this method directly on its injected ProjectManager instance.


    Code:
    	
    	/* (non-Javadoc)
    	 * @see com.pvconfigurator.core.service.ProjectManagerI#updateProject(com.pvconfigurator.core.domain.Project)
    	 */
    	@Transactional
    	public void updateProject(Project project) {
    		log.debug("updateProject() called by " + this);
    		getDao().update(project);
    	}
    The Dao is also a spring injected bean.


    In my single application context file I have the following:

    Code:
    	<tx:annotation-driven  />
    Logging indicates that the bean that is injected into the controller (as well as the one called upon by the controller) is the real bean, not a proxy.

    If I instead mark the handleRequest method of the controller with @Transactional, everything works (except that having the transaction started at this level creates a host of other issues)

    I've tried not programming to an interface and specifying the class-based proxy - same deal.

    I also tried to weave AspectJ at load time. nothing.

    What in the world am I doing wrong?

  • #2
    I suspect that both classes are loaded in different ApplicationContext and that also your tx:annotation driven is in a different xml file then the one where your service is defined.

    Comment


    • #3
      Thanks for the response Marten. Everything is in a single ApplicationContext xml config file. Furthermore, when the controller's handlerequest method is marked with the transactional annotation, it works--this being the case even though the controllers are defined in the dispatchservlet, while tx:annotation-driven is in the applicationContext. Any other ideas? Is there anything that I might have done that could be preventing the autoproxying of the service bean? What spring classes can I do some logging in in order to debug this?


      Here's what I have applicationcontext.xml
      Code:
      	<tx:annotation-driven  />
      
      [...]
      
      
      	<bean id="projectManager" class="com.pvconfigurator.core.service.ProjectManagerImp">		
      		<property name="persistentDesignManager" ref="persistentDesignManager"/>
      		<property name="dao" ref="projectDao" />
      		<property name="secureObjectManager" ref="secureObjectManager"/>
      	</bean>
      
      
      	<bean id="jpaProjectDao" class="com.pvconfigurator.core.dao.jpa.JpaProjectDaoImp" factory-method="getInstance">
      		<property name="entityManagerFactory" ref="entityManagerFactory"/>
      	</bean>
      
      
      
      	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      	  <property name="entityManagerFactory" ref="entityManagerFactory" />
      	  <property name="jpaDialect" ref="jpaDialect" />
      	</bean>
      	<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.TopLinkJpaDialect"/>
      Dispatchservlet

      Code:
      	<bean id="projectController" class="com.pvconfigurator.core.web.ProjectController">	
      		<property name="validator" ref="projectValidator"/>
      		<property name="successView" value="redirect:project.html?action=view"/>
      		<property name="defaultDeleteSuccessView" value="redirect:myhome.html"/>
      		<property name="projectManager" ref="projectManager"/>
      		<property name="systemDesignManager" ref="systemDesignManager"/>
      		<property name="secureObjectManager" ref="secureObjectManager"/>
      		<property name="validDeleteSuccessViews">		
      			<list>
      				<value>redirect:projects.html</value>
      				<value>redirect:myhome.html</value>
      			</list>
      		</property>		
      	</bean>

      ProjectManagerImpl:

      Code:
      	@Transactional
      	public void updateProject(Project project) {
      		getDao().update(project);
      	}

      logging shows that updateProject is being called on an instance of this class, not a proxy


      ProjectController

      Code:
      	@Override
      	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
      		Project project = null;
      		String action = request.getParameter("action");
      		Map<String, Object> model = (Map<String, Object>) errors.getBindingResult().getModel();	
      		if ("edit".equals(action)) {
      			String id = request.getParameter("id");	
      			project = projectManager.getProjectWithId(Integer.parseInt(id));			
      			if (project == null) throw new ObjectNotFoundException();			
      			secureObjectManager.confirmAuthorityToWrite(project);						
      			projectManager.updateProject(project);
      		} 
      		
      		else if ("create".equals(action)) { 
      			User creator = ((UserDetailsImp) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUser();
      			project = (Project)command;
      			project.setCreator(creator);
      			projectManager.saveProject(project);
      		}			
      		
      		model.putAll(referenceData(request, errors.getTarget(), errors));		
      		model.put("pageTitle", generatePageTitle(request));	
      		model.put("id", project.getObjectId());	
      		model.put("dateFormat", dateFormat);	
      		return new ModelAndView(getSuccessView(), model);				
      	}

      side question: If a persistent object is retrieved from the database outside of the transaction (i.e., in the formBackingObject()), and then updated in a transactional method in a service class called by onsubmit, the entitymanger won't have any difficulty determining the identity of the persistent object?

      Comment


      • #4
        Ah ne'er mind. The bean was autoproxying. It was a totally different issue. thx anyways.

        Comment

        Working...
        X