0

I want to read properties file keys and I found that there is the classpath attribute to set in the @PropertySource annotation :

@Configuration
@PropertySources({
    @PropertySource("classpath:config.properties"),
    @PropertySource("classpath:db.properties")
})
public class AppConfig {
    //...
}

Where should the properties file be placed and how to know the classpath in the annotation ?

Hash
  • 4,647
  • 5
  • 21
  • 39
pheromix
  • 18,213
  • 29
  • 88
  • 158
  • This doesn't set the classpath attribute. It tells Spring that it should load properties from a resource named config.properties, which is in the classpath, in the default package. – JB Nizet Aug 26 '16 at 06:42
  • ok , so how to know the value of that classpath in the default package ? and what is this default package ? – pheromix Aug 26 '16 at 06:43
  • 1
    You don't seem to understand what the classpath is. When you start your Java application, for example with `java -cp a.jar:b.jar:someDir`, then all the classes and resources located in a.jar, b.jar, and someDir are in the classpath. That's where Java looks for the classes of your program. So, according to the annotations above, config.properties, and assuming the classpath is `a.jar:b.jar:someDir`, then config.properties must be at the root of a.jar, at the root of b.jar, or in the directory `someDir`. – JB Nizet Aug 26 '16 at 06:47

3 Answers3

5

What is class path ?

The class path is the path that the Java runtime environment searches for classes and other resource files.

How to identify classpath ?

Check your IDE, what all in build path. Folders in Build Path are in classpath. You can add any number of folders and files in classpath explicitly.

You can access anything within folders/packages of classpath can be accessed relatively :)

Classpath

Refer

Community
  • 1
  • 1
Viswanath Lekshmanan
  • 9,945
  • 1
  • 40
  • 64
0

You have two options

  1. Define shared.loader in your /conf/catalina.properties. Example:

    shared.loader = D:\data\properties

  2. If you are using maven, put your properties in /src/main/resources

alex
  • 8,904
  • 6
  • 49
  • 75
-1

I found the location in this tuto.

pheromix
  • 18,213
  • 29
  • 88
  • 158