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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:13:27+00:00 2026-05-23T21:13:27+00:00

I have a scenario configuring Spring Security on embedded Jetty which seems to be

  • 0

I have a scenario configuring Spring Security on embedded Jetty which seems to be somewhat solved if I make use of JavaConfig to configure the Jetty server.

As a result, it’s looking like JavaConfig rather than XML might be the better option for large chunks of the project. However, there are some niceties in the XML namespaces, like <context:component-scan /> which aren’t readily available in a @Configuration setting.

I have discovered that ApplicationContextAware is honored for @Configuration classes, so the following is possible

@Configuration
public class FooConfig implements ApplicationContextAware {
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        ((AnnotationConfigApplicationContext) applicationContext).scan("org.example");
    }
}

The alternative, which is documented, is to have the @Configuration class use an @ImportResource annotation and pull in an existing XML file:

@Configuration
@ImportResource("applicationContext-withComponentScan.xml")
public class BarConfig {}

I guess the question is “Is it bad form to abuse ApplicationContextAware in this way, or is it really not abuse”? Something just feels oddly dirty about the approach so I’d not be surprised if the Spring guys had covered this in some way or another that I’ve not spotted.

For the interested, the problem relates to scanning a Jersey setup with @Resource and @Provider classes that I’d rather not have to manually manage entries in a class/XML configuration.

  • 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-23T21:13:28+00:00Added an answer on May 23, 2026 at 9:13 pm

    Is it bad form to abuse ApplicationContextAware in this way, or is it really not abuse

    Yes, this is bad form. If you’re going to fetch things out of the context manually, you may as well not bother with dependency injection in the first place.

    However, your second option (@ImportResource("applicationContext-withComponentScan.xml")) is a good one – this is current best practice when you want to use these XML macros in combination with annotation-style config.

    A third option is to use the current milestone build of Spring 3.1, which adds a way of doing these things all in Java, using @Feature. This is not yet production-ready, though.

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

Sidebar

Related Questions

I have a scenario. (Windows Forms, C#, .NET) There is a main form which
I have a scenario in a system which I've tried to simplify as best
I have a scenario where I use Httpclient to get the HTML repsonse of
I have a scenario which is as follows:- A form containing 2 grids. The
we have this scenario: A server which contains needed data and client component which
I have a scenario where I have some text, which should be user-selectable. The
I have a scenario in which I want user to be able to start
I have scenario where thread updates form's control. I followed http://msdn.microsoft.com/en-us/library/ms171728.aspx to make it
I have a scenario where I use threads. Firstly I have a folder where
I have following scenario. Some people use approach 1 and some use approach 2.

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.