Announcement Announcement Module
No announcement yet.
Can I use @Values from a custom PropertySource in java config files? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can I use @Values from a custom PropertySource in java config files?

    I've followed
    and built a custom class implementing PropertySource and got it working.
    In a bean class I can get hold of Environment and successfully get values.

    But, can I use this in java config classes?
    In other words I want to @Import something and then use @Value to hit my custom class for properties.

    The big story is that I'm adding Spring into a giant legacy app that has it's own custom preferences API that holds all the usual properties such as database user name. I'm trying to write a clean API to use it within the Spring config files.

    It feels to me like there is a step missing in that blog post for using all this magic with web apps, but then again it's probably me that's missing something.

    thanks a lot

  • #2
    and the answer was in the javadocs for @Configuration

    inside a spring config file use

    @Autowired Environment env;

    (note that the Javadoc says you can use @Inject but that's not working)

    then you can

    public Foo getMyFoo(){
    String user = env.getProperty("USER_NAME");
    return new Foo(user);


    • #3
      Can I use @Values from a custom Property Source in java config files so there is a unique classification in all perspectives
      so we will be confident for performing action.
      Personal Trainer Overland Park
      Last edited by Raul John; Mar 3rd, 2012, 12:40 AM.