无法从类访问application.properties属性

时间:2019-01-14 11:26:49

标签: spring-boot

application.properties文件已在src / resources文件夹中创建;它包含:

ARTICLE_XML = D:\\Projets\\Oxalys\\XML\\Exemple_export_Articles_.xml
FOURNISSEUR_XML = D:\\Projets\\Oxalys\\XML\\Exemple_export_Fournisseurs.xml
FACTURE_XML = D:\\Projets\\Oxalys\\XML\\Exemple_export_Factures.xml
COMMANDE_XML = D:\\Projets\\Oxalys\\XML\\Exemple_export_Commandes.xml
RECEPTION_XML = D:\\Projets\\Oxalys\\XML\\Exemple_export_Réceptions.xml

ARTICLE_CSV = D:\\Projets\\Oxalys\\CSV\\
FOURNISSEUR_CSV = D:\\Projets\\Oxalys\\CSV\\
FACTURE_CSV = D:\\Projets\\Oxalys\\CSV\\
COMMANDE_CSV = D:\\Projets\\Oxalys\\CSV\\
RECEPTION_CSV = D:\\Projets\\Oxalys\\CSV\\

在类中,我引用了一个属性:

public class Article {

    @Autowired
    private static Environment env;
    static File xml = new File(env.getProperty("ARTICLE_XML")); // it is the line 31 in the console error
    static File out = new File(env.getProperty("ARTICLE_CSV") + "out_article.csv");

    public static synchronized void process() throws IOException, InterruptedException {

        Thread th = new Thread() {
            @Override
            public void run() {
                try {
                       .....

编译并制作了Maven软件包后,当我运行该应用程序时,出现控制台错误:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.axian.oxalys.main.App.main(App.java:22)
Caused by: java.lang.NullPointerException
    at com.axian.oxalys.classes.Article.<clinit>(Article.java:31)
    ... 1 more

那怎么了?

0 个答案:

没有答案