Java Spring autowire configuration error

I need to autowire a bean in Spring and I am having some difficulty.

I believe everything as described here was followed:
but I keep getting this error in the Java Concole:

SEVERE: Caught exception while allowing TestExecutionListener [] to prepare test instance [com.Chelsea.web.controller.PatOrdersControllerTest@6dabbec4]
java.lang.IllegalStateException: Failed to load ApplicationContext
	at org.springframework.test.context.TestContext.getApplicationContext(

Open in new window

This is the Test class
//Test class
package com.Chelsea.web.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.context.ContextConfiguration;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.ModelAndView;
import com.Chelsea.web.controller.helper.RandomString;
import com.chelsea.service.LookupService;

import static org.junit.Assert.*;
import static org.springframework.test.web.ModelAndViewAssert.*;

@ContextConfiguration(locations = {
	    "classpath:applicationContext-services.xml" })
public class TestControllerTest {

    private LookupService lookupService;

	public void testLookupService() throws Exception {
		logger.debug("Before : testLookupService");
		logger.debug("After : testLookupService");


Open in new window

In the xml file applicationContext-services.xml I have the bean configured:
	<bean id="lookupService" class="com.Chelsea.web.service.LookupService">

Open in new window

In addition the annotation-config is in the same file as well as the base package is configured.
 	<context:annotation-config />
	<context:component-scan base-package="com.Chelsea.service" />

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What is the folder structure of your project?
Is this a maven project where the spring xml config files reside in src/main/resources folder?
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Ok, so from what you've posted, I think the problem is here... (line 38, based on the above posted snippet)
import com.chelsea.service.LookupService;

... but ...

<bean id="lookupService" class="com.Chelsea.web.service.LookupService">

It appears that you have 2 different LookupService classes, you are asking Spring to create one version in the xml and then asking for a different version to be AutoWired and hence it can't find it and throws the error.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
onaled777Author Commented:
Thank you!
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
You're welcome!!
well spotted @mccarl !
mccarlIT Business Systems Analyst / Software DeveloperCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.