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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:04:51+00:00 2026-06-04T16:04:51+00:00

Trying to make some experiments with Spring MVC and Spring Security: @Controller @RequestMapping(/auth) public

  • 0

Trying to make some experiments with Spring MVC and Spring Security:

@Controller
@RequestMapping("/auth")
public class AuthController {   
    @Autowired
    // @Qualifier("userDetailsService") - tried adding this
    private MyUserDetailsService userDetailsService;
    ...
}

// @Scope("singleton") - tried adding this
@Service("userDetailsService")
public class MyUserDetailsService implements UserDetailsService {
    ...
}

Complete context.xml that I have:

<?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"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:security="http://www.springframework.org/schema/security"
    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
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.0.xsd">

    <!-- ORIGINAL springmvc-servlet.xml -->
    <mvc:annotation-driven />
    <mvc:resources mapping="/static/**" location="/static/" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

    <context:annotation-config />
    <context:component-scan base-package="com.xxxxxxxxx" />
    <!-- end ORIGINAL springmvc-servlet.xml -->

    <!-- FROM springmvc-security.xml -->
    <security:global-method-security secured-annotations="enabled">
    </security:global-method-security>

    <security:http auto-config="true" access-denied-page="/auth/denied">
        <security:intercept-url pattern="/admin/*" access="ROLE_ADMIN"/>        
        <security:intercept-url pattern="/user/*" access="ROLE_USER"/>
        <security:intercept-url pattern="/auth/login" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
        <security:intercept-url pattern="/auth/register" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
        <security:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
        <security:form-login login-page="/auth/login" authentication-failure-url="/auth/login?login_error=true" default-target-url="/user"/>
        <security:logout logout-url="/auth/logout" logout-success-url="/" invalidate-session="true"/>
        <security:openid-login authentication-failure-url="/login?login_error=t" user-service-ref="openIdUserDetailsService" />
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider user-service-ref="userDetailsService" />
    </security:authentication-manager>
    <!-- end FROM springmvc-security.xml -->    
</beans>

For some reason, there are 2 instances of MyUserDetailsService created. The first one is used by Spring Security and the second one is injected to AuthController. What’s the right approach in case I want to have a single instance of MyUserDetailsService?

  • 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-04T16:04:55+00:00Added an answer on June 4, 2026 at 4:04 pm

    You haven’t shown enough configuration to be certain, but I’d bet money that you’re confused about how Spring ApplicationContexts should be managed in a Spring MVC app. My answer to another question about the same problem is almost certainly what you need to read:

    Declaring Spring Bean in Parent Context vs Child Context

    You’ve most likely declared your service bean (either explicitly or with a component-scan) in both the root and child contexts of your app. Being a service bean, it should live only in the root context. You may also benefit from reading this answer:

    Spring XML file configuration hierarchy help/explanation

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

Sidebar

Related Questions

I'm trying to make some changes in an Visual Studio 2008 MVC 1 code,
I'm trying to make some keen experiments about android event handler... Let say.., I
I'm trying to make some text bold using HTML, but I'm struggling to get
I'm trying to make some social share buttons at my site, but the urls
I'm trying to make some communication for my PIC devices and I use UDP
I'm trying to make some kind of top for some game stadistics Table it's
I'm trying to make some utils for using with sqlite databases. For that I
I'm trying to make some sort of delay in the view controllers changing. I
I am trying to make some SPARQL queries using vc-db-1.rdf and q1.rq from ARQ
i'm trying to make some sort of Business Simulation Game and everything is working

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.