Right path to applicationContext.xml using ClassPathXmlApplicationContext

后端 未结 5 1790
渐次进展
渐次进展 2021-02-03 13:03

I have working web-application with applicationContext.xml in WEB-INF/config/applicationContext.xml. Now i need to implement some testing tool as standalone application, that ca

相关标签:
5条回答
  • 2021-02-03 13:37

    This is the reason why I prefer to put all configuration files in classes folder. In fact, using Maven, you can put all these files in src/main/resources. Then, in your test files you can access as 'classpath:applicationContext.xml'.

    0 讨论(0)
  • 2021-02-03 13:38

    In a local test scenario, you are not inside a Jar, so you don't need Classpath-based access. Use FileSystemXmlApplicationContext instead.

    Probably something like this:

    private static final ApplicationContext ac =
        new FileSystemXmlApplicationContext(
            "src/WEB-INF/config/applicationContext.xml"
        );
    

    (paths are relative from the execution directory)

    0 讨论(0)
  • 2021-02-03 13:52

    please go to property>Java Build Path>Source of your project check the classpath and add the directory before WEB-INF in the classpath. definitely it's work

    0 讨论(0)
  • 2021-02-03 13:54
    private static final ApplicationContext ac =
        new FileSystemXmlApplicationContext(
            "/WEB-INF/config/applicationContext.xml"
        );
    
    0 讨论(0)
  • 2021-02-03 14:03
    private static final ApplicationContext ac =
    new FileSystemXmlApplicationContext(
        "/WEB-INF/config/applicationContext.xml"
    );
    
    0 讨论(0)
提交回复
热议问题