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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:52:04+00:00 2026-06-13T03:52:04+00:00

I’m relatively new to Spring and even newer to annotations and autowiring. I can’t

  • 0

I’m relatively new to Spring and even newer to annotations and autowiring. I can’t figure out how to wire my beans. The idea is to switch between CacheService and NoCacheService by changing the application-config.xml but I cannot get past the exception.

Exception

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Service' defined in ServletContext resource [/WEB-INF/application-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [webapp.Services]: Specified class is an interface
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)
<snip>

Classes:

package webapp;
interface Service {
    List<String> get();
}

@Service("cache")
CacheService implements Service {
    //from cache then from IO bound source
    @Autowired
    public CacheService(int v1, int v2)
    ...
}

@Service("nocache")
NoCacheService implements Service {
    //from IO bound source
    ....
}

Controller:

@RequestMapping("/")
@Controller
public class ServiceController {

    @Autowired
    Service service;
    ...
}

application-config xml:

<mvc:annotation-driven />
<context:component-scan base-package="webapp"/>

<beans:bean id="Service" class="webapp.Service">
    <beans:property name="cache" ref="cache" />
</beans:bean>


<beans:bean id="cache" class="webapp.CacheService">
    <beans:constructor-arg index="0" value="50"/> <!-- v1 -->
    <beans:constructor-arg index="1" value="100"/> <!-- v2 -->
</beans:bean>

<beans:bean id="nocache" class="webapp.NoCacheService">
</beans:bean>
  • 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-13T03:52:06+00:00Added an answer on June 13, 2026 at 3:52 am

    You can choose to wire things using annotations or xml, in this specific case there are beans which are being configured both ways and that will cause the issues you are seeing. Let me try and enumerate some changes:

    .1. Remove <beans:bean id="Service" class="webapp.Service">
    <beans:property name="cache" ref="cache" />
    </beans:bean>
    as your webapp.Service is an interface and the reason for your error message.

    .2. It will be better to instantiate CacheService through configuration, so just remove @Service annotation from it and retain only this:

    <beans:bean id="cache" class="webapp.CacheService">
        <beans:constructor-arg index="0" value="50"/> <!-- v1 -->
        <beans:constructor-arg index="1" value="100"/> <!-- v2 -->
    </beans:bean>
    

    .3. NoCacheService need not be in the xml file, it can be instantiated using component-scan the way you have already done.

    .4. Now to injct the CacheService or NoCacheService, since there are two instances you have to indicate which one to inject into the Controller, which you can do this way:

    @RequestMapping("/")
    @Controller
    public class ServiceController {
    
        @Autowired @Qualifier("cache") //or noCache
        Service service;
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.