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

  • Home
  • SEARCH
  • 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 8205819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:25:01+00:00 2026-06-07T08:25:01+00:00

Using Spring MVC, I have this Controller class: @Controller public class LoginController { @Autowired

  • 0

Using Spring MVC, I have this Controller class:

@Controller
public class LoginController {
    @Autowired
    private LoginService loginService;
    // more code and a setter to loginService
}

LoginService is an interface, whose only implementation is LoginServiceImpl:

public class LoginServiceImpl implements LoginService {
    //
}

My project-name-servlet.xml file is this one:

<?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-2.5.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-3.0.xsd">   
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/" />
        <property name="suffix" value=".jsp" />
    </bean>
    <bean id="loginService" class="my.example.service.impl.LoginServiceImpl" />
    <bean class="my.example.controller.LoginController" />
</beans>

The problem is, loginService is not injected into the controller. If I specify the injection in the XML file as below, it works:

    <bean id="loginService"
        class="may.example.service.impl.LoginServiceImpl" />
    <bean class="my.example.controller.LoginController">
        <property name="loginService" ref="loginService"></property>
    </bean>

Why does this happen? Shouldn’t the only implementing bean be injected in an interface-typed injection point?

  • 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-07T08:25:10+00:00Added an answer on June 7, 2026 at 8:25 am

    You have to add a AutowiredAnnotationBeanPostProcessor for the Autowiring to work – It is byType by default, so you don’t have to do anything explicit to inject your loginService into your LoginController. Like the link says, you can put a <context:annotation-config/> or <context:component-scan/> to automatically register a AutowiredAnnotationBeanPostProcessor.

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

Sidebar

Related Questions

This is an example of using ThrowawayController in Spring MVC: public class DisplayCourseController implements
I am using spring 3 mvc/security frameworks. I have created a Controller class that
I am using Spring MVC with annotation configuration. I have a controller class for
I am using Spring MVC 3, NetBeans I have the following model, public class
I'm using Spring MVC and jquery autocomplete, my spring controller looks like this @RequestMapping(value
See the following Mock Test by using Spring/Spring-MVC public class OrderTest { // SimpleFormController
I have a Spring MVC controller with an action that's called using AJAX. @SessionAttributes({userContext})
I'm trying to make this 2-player web game application using Spring MVC. I have
I'm working on a test application using Spring MVC. I have a Person class
I have an MVC project similar to this... Model Public Class ItemDetails Public Property

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.