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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:42:00+00:00 2026-05-16T10:42:00+00:00

I have a bean definition in Spring and it’s proxy counterpart which is meant

  • 0

I have a bean definition in Spring and it’s proxy counterpart which is meant to be used everywhere:

<bean name="my.Bean" class="org.springframework.aop.framework.ProxyFactoryBean" scope="prototype">
  <property name="proxyInterfaces" value="my.Interface"/>
  <property name="target" ref="my.BeanTarget"/>
  <property name="interceptorNames">
    <list>
      <value>someInterceptor</value>
    </list>
  </property>
</bean>

<bean name="my.BeanTarget" class="my.InterfaceImpl" scope="prototype">
  <property name="foo" ref="bar"/>
</bean>

This all works well; and in pre-Spring v3 world I was using it like

ApplicationContext ctx = ...;
my.Interface foo = (my.Interface) ctx.getBean("my.Bean"); // cast is necessary

In Spring 3 it became possible to do type safe lookups, e.g.:

my.Interface foo = ctx.getBean(my.Interface.class);

Again, this works well for ordinary beans whereas for proxied beans I am getting my.BeanTarget instead of my.Bean. I have tried to inline my.BeanTarget (as shown in Spring documentation) to make it hidden, but all I got was

org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [my.Interface] is defined: expected single bean but found 0: 

So is it possible to use type safe bean lookups with proxied beans and if yes – how?

  • 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-16T10:42:01+00:00Added an answer on May 16, 2026 at 10:42 am

    The problem here is the scope="prototype" on your ProxyFactoryBean.

    The context will only eagerly-initialize singleton bean definitions. Beans of non-singleton scope are only initialized when asked for. This means that when you ask the context for beans of a given type, the context cannot initialize those non-singleton beans in order to ask them for their type, it has to go purely on the information in the bean definition.

    In the case of ProxyFactoryBean, the type of the generated proxy is determined by complex logic that requires the bean to be fully initialized. Without that initialization, ProxyFactoryBean can only report the target type as null.

    I can’t say a way around this, other than using a singleton bean definition, or explicitly asking for the bean by name, e.g.

    <bean id="my.Interface"> class="ProxyFactoryBean"... >
    

    and then:

    ctx.getBean(MyInterface.class.getName());
    

    Here, we use the convention of bean names being the interface they implement.

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

Sidebar

Related Questions

I have two Spring proxies set up: <bean id=simpleBean class=org.springframework.aop.framework.ProxyFactoryBean> <property name=target> <ref local=simpleBeanTarget/>
I am using spring to initialise my beans. I have configured a bean which
I have a large application spread across multiple Spring bean definition xml files. In
Have two bean definitions: file a.xml <bean id=A class=com.A> <property name=bClass ref=B/> </bean> file
Given I have a Spring bean configured as @Service(myService) public class DefaultService extends MyService
when I have a bean <bean name=myBean class=mypackage.myBean> <property name=otherBean ref=otherBeanRef /> </bean> and
I have a bean which I map to the database using Hibernate. I'm using
I have a bean of type string[] which has two or more values. I
I have a problem with selectInputDate: I have a backing bean which I am
I have a method invoking bean which calls a method to perform some sort

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.