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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:31:06+00:00 2026-05-22T01:31:06+00:00

Is it correct that one can create spring beans using just the @Component annotation

  • 0

Is it correct that one can create spring beans using just the @Component annotation as long as context component scanning is configured?

Using spring 3.0.5 with Java 6.

My test case is:

@ContextConfiguration(locations={"classpath:spring-bean.xml"})

public class ServerServiceUnitTest extends AbstractJUnit4SpringContextTests {
    @Autowired
    private ServerService serverService;

    @Test
    public void test_server_service() throws Exception {
           serverService.doSomething();
           //additional test code here
        }
}

The spring-bean.xml file contains:

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

My class I want to be a bean is:

@Component("ServerService")
public class ServerServiceImpl implements ServerService {
    private static final String SERVER_NAME = "test.nowhere.com";
        //method definitions.....'
}

Should that not be sufficient for spring to instantiate the ServerService bean and do the autowiring?

The error I get is:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [serversystem.ServerService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

I’m sure I’m missing something simple.

  • 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-22T01:31:08+00:00Added an answer on May 22, 2026 at 1:31 am

    You have not defined in your spring-beans.xml the <context:component-scan> element:

    <context:component-scan base-package="the.package.with.your.service"/>
    

    The inclusion of

    <context:annotation-config/>
    

    only allows you to use @Required, @Autowired, and @Inject annotations for configuration. By specifying the <context:component-scan>, you are telling Spring where to look for @Component annotations.

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

Sidebar

Related Questions

can i somehow compare two numbers in regex? i want regex that is correct
How can I validate that my ASPNET AJAX installation is correct. I have Visual
What is the correct syntax to create objects in javascript that will work across
I'm attempting to create a function where I can pass names and values that
I have been using Java's ConcurrentMap for a map that can be used from
My latest problem is one that I already have a solution for, it just
Am I correct in assuming that the only difference between "windows files" and "unix
Am I correct in assuming that I always need to explicitly deploy referenced assemblies
Is it correct to say that typically user_dump_dest is on a local drive? If
Is it correct to assume that JQuery is not actually an implementation of ECMA

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.