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 762665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:25:45+00:00 2026-05-14T16:25:45+00:00

I have a strange behaviour when autowiring I have a similar code like this

  • 0

I have a strange behaviour when autowiring

I have a similar code like this one, and it works

@Controller
public class Class1 {
    @Autowired
    private Class2 object2;
    ...
}

@Service
@Transactional
public class Class2{
   ...
}

The problem is that I need that the Class2 implements an interface so I’ve only changed the Class2 so it’s now like:

@Controller
public class Class1 {
    @Autowired
    private Class2 object2;
    ...
}

@Service
@Transactional
public class Class2 implements IServiceReference<Class3, Long>{
   ...
}

public interface IServiceReference<T, PK extends Serializable> {
    public T reference(PK id);
}

with this code I get a org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type for Class2.
It seems that @Transitional annotation is not compatible with the interface because if I remove the @Transitional annotation or the implements IServiceReference<Class3, Long> the problem disapears and the bean is injected (though I need to have both in this class). It also happens if I put the annotation @Transitional in the methods instead of in the Class.

I use Spring 3.0.2 if this helps.

Is not compatible the interface with the transactional method?
May it be a Spring bug?

  • 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-14T16:25:46+00:00Added an answer on May 14, 2026 at 4:25 pm

    The problem is that your Class1 needs a reference to IServiceReference and not the concrete reference of Class2

    @Controller
    public class Class1 {
    @Autowired
    private IServiceReference object2;
        ...
    }
    

    The reason this is that Spring is creating a dynamic proxy for classes that you marked @Transactional. Thus when Class2 is created its wrapped in a Proxy object that is obviously not of type Class2 but is of type IServiceReference.

    If you want the behavior of using Class2 with proxy support you will have to turn on CGLIB
    Read below:

    From Springs Doc:

    Spring AOP defaults to using standard
    J2SE dynamic proxies for AOP proxies.
    This enables any interface (or set of
    interfaces) to be proxied.

    Spring AOP can also use CGLIB proxies.
    This is necessary to proxy classes,
    rather than interfaces. CGLIB is used
    by default if a business object does
    not implement an interface. As it is
    good practice to program to interfaces
    rather than classes, business classes
    normally will implement one or more
    business interfaces. It is possible to
    force the use of CGLIB, in those
    (hopefully rare) cases where you need
    to advise a method that is not
    declared on an interface, or where you
    need to pass a proxied object to a
    method as a concrete type.

    It is important to grasp the fact that
    Spring AOP is proxy-based. See the
    section entitled Section 6.6.1,
    “Understanding AOP proxies” for a
    thorough examination of exactly what
    this implementation detail actually
    means.

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

Sidebar

Related Questions

This is a very strange behaviour. If I have something like this (time interval
I've noticed some very strange behaviour today in Code Igniter. I have this locations
I have very strange behaviour of Java Date class: System.out.println(new Date().toGMTString()); long l =
Why this two functions have the strange behaviour of when I click on thead,
I have this strange behaviour in VS2010 where any modifications I make to keyboard
I'm seeing a strange behaviour, hopefully someone out there can explain this. I have
I have several forms with this strange behaviour. For instance I have this form
I have strange behaviour with firefox (other browser works good). I have rule: .feed.input.community
I have a strange behaviour, maybe I'm missing something. I have this DOM element
I have a strange behaviour with the code below: function update(txt, _) { #text

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.