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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:57:49+00:00 2026-05-29T08:57:49+00:00

is there some simple way to inject Properties class loaded with a file from

  • 0

is there some simple way to inject Properties class loaded with a file from the classpath into EJB (3.1)?

Something like this:

@Resource(name="filename.properties", loader=some.properties.loader)
private Properties someProperties;

Thank you,

Bozo

  • 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-29T08:57:50+00:00Added an answer on May 29, 2026 at 8:57 am

    As bkail said, you can achieve this in the following way. I am not sure what your loader=some.properties.loader really meant, so skipped doing anything with that, but provided option for that in case you want to load using the loader.getClass().getResourceAsStream ("filename.properties");

    First define your injection type

    @BindingType
    @Retention(RetentionPolicy.RUNTIME)
    @Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD,
            ElementType.PARAMETER })
    public @interface PropertiesResource {
    
        @Nonbinding
        public String name();
    
        @Nonbinding
        public String loader();
    
    }
    

    Then create a producer for that

    public class PropertiesResourceLoader {
    
        @Produces
        @PropertiesResource(name = "", loader = "")
        Properties loadProperties(InjectionPoint ip) {
            System.out.println("-- called PropertiesResource loader");
            PropertiesResource annotation = ip.getAnnotated().getAnnotation(
                    PropertiesResource.class);
            String fileName = annotation.name();
            String loader = annotation.loader();
            Properties props = null;
            // Load the properties from file
            URL url = null;
            url = Thread.currentThread().getContextClassLoader()
                    .getResource(fileName);
            if (url != null) {
                props = new Properties();
                try {
                    props.load(url.openStream());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
    
            return props;
        }
    }
    

    Then inject it into your Named component.

    @Inject
    @PropertiesResource(name = "filename.properties", loader = "")
    private Properties props;
    

    I did this looking into the weld documentation where the @HttpParam is given as an example here. This is as per weld 1.1.0, in weld 1.0.0, the getting annotation can be done like this

    PropertiesResource annotation = ip.getAnnotation(PropertiesResource.class);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some simple way to calculate a Weeknumber value from a date value
is there a simple way to persist some of the fields in another class
Is there some simple way or how to integrate sqlite database into gtk.TreeModel (TreeView)?
Is there some simple way to send out a ping-style message to a remote
Is there any (simple) way to get some control of the order in which
Is there a simple way, without .NET? I've found some libraries but none for
I am working on a cms and there are some simple parameters like number
It feels like there must be some semi-simple solution to this, but I just
Is there some simple way of capturing and making assertions about logged messages with
Is there some relatively simple way to programmatically include source code lines to python

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.