gpt4 book ai didi

java - 配置文件放在哪里

转载 作者:太空宇宙 更新时间:2023-11-04 08:23:11 26 4
gpt4 key购买 nike

我正在编写java应用程序。我正在使用 Spring MVC、Spring Security、Hibernate 和 Tiles。我在我的项目中使用maven。每当我执行网络应用程序时,我都会遇到异常:

0 [main] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
281 [main] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Sat Feb 04 03:15:50 IST 2012]; root of context hierarchy
625 [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [resources/security-app-context.xml]
640 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [resources/security-app-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [resources/security-app-context.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at ...........
..............

我尝试将 security-app-context.xml 放在任何地方,但它没有帮助,而且我不断收到此异常。

这是我的 POM 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>success.green-wheels</groupId>
<artifactId>green-wheels-project</artifactId>
<version>1</version>
<packaging>war</packaging>

<name>web-app-module</name>
<url>http://maven.apache.org</url>

<properties>
<org.springframework.version>3.1.0.RELEASE</org.springframework.version>
<org.apache.tiles.version>2.2.2</org.apache.tiles.version>
<org.hibernate.version>3.3.2.GA</org.hibernate.version>
</properties>
<dependencies>
...Some dependencies to Spring, Hibernate and so
</dependencies>

<build>
<finalName>${artifactId}</finalName>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src/success/greenWheels/dataAccess/hibernate/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<directory>web</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>

这是我的目录结构: enter image description here

出了什么问题?我应该将 security-app-context.xml 放在哪里才能使其正常工作?

我想将所有配置文件放在一个文件夹中。我该怎么做?

最佳答案

如果将 /resources 目录放在 WEB-INF/classes 下,则该目录将位于 CLASSPATH 中。

关于java - 配置文件放在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9137625/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com