0

I have a controller

package com.controller;
    @Controller
    public class MyController{
    @Autowired
    private ISessionHolder holder;
    }

In my config xml:

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

<bean id="sessionholder" class="com.session.SessionHolder" scope="session">
    <aop:scopedProxy/>
</bean>

However I get the exception

no matching bean found for type ISessionHolder used in MyController.

But if i remove the bean definition for the sessionholder in the XML and annotate, it works fine.

@Component
@ScopedProxy
public class SessionHolder{
//
}

Are annotated classes instantiated first Or is there a specific order?

Srini
  • 420
  • 1
  • 5
  • 17
  • Does it work without the scope="session"? – gkamal Aug 02 '12 at 08:06
  • Are you sure that the xml file is being used? – gkamal Aug 02 '12 at 08:07
  • @gkamal edited my xml definition. – Srini Aug 02 '12 at 08:10
  • @gkamal will it work if I move the below my bean definition – Srini Aug 02 '12 at 08:14
  • Did you remove the @Component annotation when the bean was defined in xml? If you have both the ids should match - use "sessionHolder" as id then the xml definition will override annotation. Otherwise you will have two beans and then autowiring will fail. – gkamal Aug 02 '12 at 08:15
  • No I removed the @component when I defined the bean in xml.kindly look at my previous comment and tell me if that is the prob. – Srini Aug 02 '12 at 08:17
  • 5
    The order doesn't matter - the configuration should work. There is something else wrong. The SessionHolder class should implement the ISessionHolder interface. – gkamal Aug 02 '12 at 08:42
  • I think gkamal is right. You should write that up as an answer. – Peter Bratton Mar 01 '13 at 15:40
  • http://stackoverflow.com/questions/15233766/what-is-the-precedence-of-spring-beans-definitions XML always gets precedence – Abhishek Garg Feb 11 '16 at 21:50

0 Answers0