我开发了一个 Spring MVC Web 应用程序。在这个应用程序中,我有两个容器,spring bean 配置文件的位置是:
/WEB-INF/dispatcher-servlet.xml
我已经更改了 spring bean cfg 文件的名称,但我还想将位置更改为:
/com/nt/cfg/applicationContext.xml
但是,Spring 不识别除/WEB-INF/
我开发了一个 Spring MVC Web 应用程序。在这个应用程序中,我有两个容器,spring bean 配置文件的位置是:
/WEB-INF/dispatcher-servlet.xml
我已经更改了 spring bean cfg 文件的名称,但我还想将位置更改为:
/com/nt/cfg/applicationContext.xml
但是,Spring 不识别除/WEB-INF/
您只需要在创建 ClassPathXmlApplicationContext 时声明 de route:
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
默认位置是资源文件夹。
希望这对您有所帮助。
答案是肯定的,您可以更改配置文件的名称和位置,但您必须让 spring 知道新的名称和位置。
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
它将从context.xml
文件加载上下文(context.xml 应该存在于类路径中)。
您可以通过将所需的 XML 文件作为参数传递给构造函数来创建新的 Applicationcontext。
因此,在更改文件的名称和位置后,您必须在此处注册以供 spring 参考,以便 spring 可以找到配置文件。