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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:35:17+00:00 2026-05-16T03:35:17+00:00

Let’s say I have following Spring config (version of Spring is 3.0.3): <?xml version=1.0

  • 0

Let’s say I have following Spring config (version of Spring is 3.0.3):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd">

   <bean id="theFactoryBean" class="wax.MyFactoryBean"/>

   <bean id="factoryBeanUser" class="wax.FactoryBeanUser">
       <!-- what should be placed here?-->
   </bean>

</beans>

I have instance of FactoryBean implementation and some other instance. I need Spring to inject to other instance FactoryBean, not the object it produces.

There are two possible ways to solve it.

First one, obvious and malfunctional:

 <bean id="factoryBeanUser" class="wax.FactoryBeanUser">
    <property name="myFactoryBean" ref="&theFactoryBean"/>
</bean>

With this config Spring throws following exception on start:

    [skipped irrelevant part]
Caused by: org.xml.sax.SAXParseException: The reference to entity "theFactoryBean" must end with the ';' delimiter.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1414)

I found this solution Spring: Getting FactoryBean object instead of FactoryBean.getObject(), this question is maked as answered and four people voted for it. So I assume that this solution might work, but currently there is something wrong in my code.

Second one, working but awkward:

public class FactoryBeanUser implements ApplicationContextAware{

private MyFactoryBean myFactoryBean;

   public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        myFactoryBean = (MyFactoryBean)applicationContext.getBean("&theFactoryBean");
   }
}

My question is it possible to make first approach functional or I should stick with a second way?

  • 1 1 Answer
  • 1 View
  • 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-16T03:35:17+00:00Added an answer on May 16, 2026 at 3:35 am

    It seems the XML parser interprets the ampersand (&) as a start of an XML-entity. You can try using ref="&amp;theFactoryBean".

    The spring docs is not clear whether this syntax is allowed in an xml file, or only with programatic lookup. But then the xml configuration is used by the app context, so I assume the &amp; should work (although it seems it has not been the best choice for a special symbol)

    Here’s why I’d suggest another thing – if you really need the factory bean rather than its product, create another bean, that does not implement FactoryBean, define a method createObject() or something like that, and use it in all factories that need it.

    A sidenote – better reference the xsd with the version included:

    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

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

Sidebar

Related Questions

Let's suppose I have an XML file like this: <?xml version=1.0 encoding=ISO-8859-1?> <MIDIFile> <Event>
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
let's say I have the following string: string s = A B C D
Let's say I have the following entity: public class Store { public List<Product> Products
Let's say, I have a .NET 2 installed. Can I programmatically install version 4
Let's say I have the following classes : public class MyProductCode { private String
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have a domain object with the following field: private Map<StatType, Double>
Let say I have the following desire, to simplify the IConvertible's to allow me
Let's say you have a class called Customer, which contains the following fields: UserName

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.