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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:52:04+00:00 2026-05-23T23:52:04+00:00

Spring provide a nice feature that allow programmer to define annotations in java source

  • 0

Spring provide a nice feature that allow programmer to define annotations in java source code to setup @Value("systemProp:defaultvalue") and other injected dependency.

However, in some case we may forget to enable the <context:annotation-config/> in a mixed XML and annotation spring program.

Is there a way, an utility method or a pattern to put in the java class to enforce the <context:annotation-config/> is not being forgotten?

  • 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-23T23:52:04+00:00Added an answer on May 23, 2026 at 11:52 pm

    Write a test case that fails if <context:anotation-config/> is not configured right.


    If you really want to check if in production, then define a default value and inject this default value.
    Then you need to check it in the constructor for example.

    public class Demo() {

      @Value("default");
      private String check;
    
      public Demo() {
         assert "default".equals(check) : "It seams that anntation-config is not enabled";
      }
    }
    

    Does not work because the Value is injected after the constructor is invoked.

    If @Autowired is supported the you can have it all in an seperate method:

    public class Demo2 {   
    
        @Autowired
        public void checkAnnotationConfigEnabled(
                              @Value("default") String check) {
            assert "default".equals(check);
        }
    }
    

    If your problem is not that you need to enable anntation-config for each class then it would be enougth to have one bean that implements this check logic. If not, and do not want to put this lines in every class, then you can do it with AspectJ intertype declartions.

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

Sidebar

Related Questions

Many modern frameworks (Spring, Hibernate) provide very nice dynamic behaviors with use of Java
Spring security has a nice feature, it remembers the url of request resource and
Spring.NET is an open source application framework that makes building enterprise .NET applications easier.
Can someone provide a regular expression for parsing name/value pairs from a string? The
I'm looking for the equivalent of Python decorators / Lisp macros / Java annotations
I create a new Date in javascript and provide it the string value of
The spring framework documentation states: In the unlikely case that a test may 'dirty'
I'm using XFire as the Web Services provider for Spring Remoting. I'm using an
I am planning to extend the basic html input tag provided by Spring to
I am using a class Foo that provides these methods: String overloadedMethod(Object) String overloadedMethod(Goo)

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.