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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:26:34+00:00 2026-06-14T20:26:34+00:00

// Two third-party factories: public class OneStaticMethodFactory { … public static Object createFactory(String oneInstanceMethodFactoryClassName)

  • 0

// Two third-party factories:

public class OneStaticMethodFactory {
 ...
 public static Object createFactory(String oneInstanceMethodFactoryClassName) {
  ...
 }
}

public class OneInstanceMethodFactory {
 ...
 public OneObject createObject() {
  ...
 }
}

// Hardwired code:

OneInstanceMethodFactory oneInstanceMethodFactory = 
 (OneInstanceMethodFactory) 
  OneStaticMethodFactory.createFactory("pkg.to.OneInstanceMethodFactory");

OneObject oneObject =
 oneInstanceMethodFactory.createObject(); 

// Attempt to replace them by Spring beans:

<bean id="oneInstanceMethodFactory" class="pkg.to.OneStaticMethodFactory"
 factory-method="createFactory">
  <constructor-arg value="pkg.to.OneInstanceMethodFactory">
  </constructor-arg>
</bean>

<bean id="oneObject" factory-bean="oneInstanceMethodFactory"
 factory-method="createObject">
</bean>

// Run Spring IoC:

java.lang.IllegalStateException: Failed to load ApplicationContext
    ...
Caused by: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'oneObject' defined in class path resource [applicationContext.xml]: 
No matching factory method found: factory bean 'oneInstanceMethodFactory'; 
factory method 'createObject()'. 
Check that a method with the specified name and arguments exists and that it is non-static.
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:528)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1015)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:605)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
        at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
        at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
        at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
        at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
        at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
        ... 26 more

To solve the problem above, how to downcast oneInstanceMethodFactory bean from compile-time type Object to runtime type OneInstanceMethodFactory in Spring? (Modification of the two third-party factory classes would not be the point on question.)

@EDIT

Thanks to the hints from @Boris Treukhov, finally i figured out that the problem had nothing to do with type downcast but indeed OneStaticMethodFactory#createFactory returned other runtime type than OneInstanceMethodFactory due to a typo myself. Now everything works as expected after the migration from the hardwired code to Spring IoC / DI above.

  • 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-06-14T20:26:36+00:00Added an answer on June 14, 2026 at 8:26 pm

    You should check that 'oneInstanceMethodFactory', is really a OneInstanceMethodFactory instance, either by checking what bean type was created with name "oneInstanceMethodFactory" through the container’s getBean() method or by examining the value returned by createFactory in the debugger.

    In my experience this exception is very straightforward, usually there’s really no such a public non-static method.

    Downcasting makes no difference because the methods are called through the reflection method which takes an Object instance as this argument. The bean type is determined by the value returned from the factory method, Spring don’t need to know the class before the bean is initialized. In fact oneObject bean depends on oneInstanceMethodFactory so the latter bean will be fully initialized before the former, and the Spring will be able to call its createObject method.

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

Sidebar

Related Questions

I have a Java class that can extend either of two third-party classes, which
There are two descriptions of the delegate: first, in a third-party assembly: public delegate
I have a project that uses two third party libraries, both of which make
Scenario: Third party web service returns datetime in two separate fields i.e. date and
Is there any third party tool available which has two richtextboxes but only a
I have two questions. Question1: How can we add a reference to a third-party
I have a folder with two files: Awesome.File.20091031_123002.txt Awesome.File.Summary.20091031_123152.txt Additionally, a third-party app handles
I need to be able to switch between two third-party applications based on the
In IIS 6 we used to do Url Rewriting with two third party components:
I currently have a project that links to two third party libraries. These libraries

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.