Java 在spring中哪里可以找到spring数据库XML文件?
我在春天遇到了以下情况 src/main/java和一些子文件夹中的spring-database.xml文件(包含hibernatebeans、sessionfactory、dao等)。 我还不能让它与保存在MySQL表中的日志用户一起工作 因此,我将spring-database.xml移到WEB-INF下,在这里它起了作用。 问题是,现在我不知道如何从java代码调用它:Java 在spring中哪里可以找到spring数据库XML文件?,java,spring,hibernate,spring-mvc,spring-security,Java,Spring,Hibernate,Spring Mvc,Spring Security,我在春天遇到了以下情况 src/main/java和一些子文件夹中的spring-database.xml文件(包含hibernatebeans、sessionfactory、dao等)。 我还不能让它与保存在MySQL表中的日志用户一起工作 因此,我将spring-database.xml移到WEB-INF下,在这里它起了作用。 问题是,现在我不知道如何从java代码调用它: ApplicationContext appContext = new ClassPathXmlApplication
ApplicationContext appContext = new ClassPathXmlApplicationContext([PATH I DON'T KNOW])
因为这不起作用,我需要那个文件中的一些bean,现在还没有找到。
我还尝试了FileSystemXmlApplicationContext而不是ClassPathXmlApplicationContext,但没有结果
理想情况下,您应该创建两个xml文件
1. mvc-config.xml or your spring-database.xml (with hibernate, sessionfactory etc)
2.application-config.xml(this should contain all the bean relates info that you should need in your project.)
将mvc-config.xml保存在WEB-INF/文件夹中,将aplication-config.xml保存在classpath中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/application-config.xml,
/WEB-INF/conf/mvc-config.xml
</param-value>
</context-param>
上下文配置位置
类路径:spring/application-config.xml,
/WEB-INF/conf/mvc-config.xml
这就是在web.xml中加载这两个文件的方式
您将能够从上面尝试的代码中获取application.xml