简体   繁体   English

java-放置配置文件的位置

[英]java - where to put the configuration files

I am writing java application. 我正在编写Java应用程序。 I am using Spring MVC, Spring Security, Hibernate and Tiles. 我正在使用Spring MVC,Spring Security,Hibernate和Tiles。 I am using maven in my project. 我在项目中使用Maven。 Whenever I execute my web app I get an exception: 每当我执行Web应用程序时,都会出现异常:

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 ...........
    ..............

I tried to put my security-app-context.xml anywhere but it doesn;t help and I keep getting this exception. 我试图将我的security-app-context.xml放在任何地方,但没有帮助,并且不断收到此异常。

Here is my POM file: 这是我的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>

Here is my directory structure: 这是我的目录结构: 在此处输入图片说明

What is wrong? 怎么了? Where should I put the security-app-context.xml in order to make it work? 我应该将security-app-context.xml放在哪里以使其起作用?

I want to put all the configuration files in one folder. 我想将所有配置文件放在一个文件夹中。 How can I do it? 我该怎么做?

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

INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [resources/security-app-context.xml]

How did you get this exeption? 你是怎么得到这个例外的? Where is your resources folder? 您的resources文件夹在哪里? I don't see it... 我没看到...

Did you use <import resource="resources/security-app-context.xml" /> in Spring config? 您是否在Spring配置中使用了<import resource="resources/security-app-context.xml" /> If yes, I guess you have to use <import resource="security-app-context.xml" /> . 如果是,我想您必须使用<import resource="security-app-context.xml" />

I'm not sure about IntelliJ IDEA , but in SpringSource Tool Suite (or Eclipse , doesn't matter) my Maven project has structure like this: 我不确定IntelliJ IDEA ,但是在SpringSource Tool Suite (或Eclipse ,没关系)中,我的Maven项目具有以下结构:

SpringSource Tool Suite Maven项目结构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM