read file in classpath

前端 未结 3 1850
长情又很酷
长情又很酷 2020-12-07 18:12

Here is what I want to do and I am wondering if there is any Spring classes that will help with implementing. I don\'t have to use spring for this particular problem, I\'m

3条回答
  •  情书的邮戳
    2020-12-07 18:54

    Try getting Spring to inject it, assuming you're using Spring as a dependency-injection framework.

    In your class, do something like this:

    public void setSqlResource(Resource sqlResource) {
        this.sqlResource = sqlResource;
    }
    

    And then in your application context file, in the bean definition, just set a property:

    
        
    
    

    And Spring should be clever enough to load up the file from the classpath and give it to your bean as a resource.

    You could also look into PropertyPlaceholderConfigurer, and store all your SQL in property files and just inject each one separately where needed. There are lots of options.

提交回复
热议问题