无法使用jetty maven插件加载外部spring配置文件

时间:2012-07-04 09:21:09

标签: spring maven jetty

我尝试在http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin中使用jetty-maven-plugin启动webapp。但我想外化我的环境配置文件。 这是我的项目层次结构:

myapp-webapp
- src
- - test
- - - ressources
- - - java
- - main
- - - ressources
- - - java
- - - webapp
- - - - WEB-INF
- - - - META-INF
- - - - templates
- - - - ressources
- - - - index.xhtml
+ target (I don't detail it)
- configuration
- - local
- - - databaseLocal.properties
- - - ... others config files
- - dev
- - test
- - prod

这是我的pom文件:

<profiles>
    <profile>
    <id>myapp-work</id>
    <activation>
        <property>
            <name>!env</name>
        </property>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <webApp>
                        <contextPath>/</contextPath>
                        <extraClasspath>configuration/local/</extraClasspath>
                    </webApp>
                    <scanTargetPatterns>
                    <scanTargetPattern>
                      <directory>configuration/local/</directory>
                      <includes>
                        <include>**/*.xml</include>
                        <include>**/*.properties</include>
                      </includes>
                    </scanTargetPattern>
                  </scanTargetPatterns>
                </configuration>
                <dependencies>
                    <dependency>
                    ...
                </dependencies>
            </plugin>
            ...
        <plugins>

我正面临着这个错误 2012-07-04 10:33:26.460:WARN ::启动上下文JettyWebAppContext @ 29b829b8 @ 29b829b8 /,文件:/ C:/ DEV / RTCworkspace / myapp / myapp-webapp / src / main / webapp /,文件: / C:/ DEV / RTCworkspace / MyApp的/ MyApp的-web应用/ SRC /主/ web应用/ org.springframework.beans.factory.BeanInitializationException:无法加载属性;嵌套异常是java.io.FileNotFoundException:无法打开类路径资源[databaseLocal.properties],因为它不存在

我发现了很多信息,但没有任何效果: - http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin - Cant find config files in Jetty + Spring + Tiles deployement - maven-jetty plugin not using correct paths

我也尝试: $ {BASEDIR} / $ {externalConfiguration.directory}

以下是启动日志的摘录(我的webapp名称是cct,我将其替换为现在):

[INFO] webAppSourceDirectory C:\DEV\RTCworkspace\cct\cct-webapp\src\main\webapp does not exist. Defaulting to C:\DEV\RTCworkspace\cct\cct-webapp\src\main\webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = C:\DEV\RTCworkspace\cct\cct-webapp\src\main\webapp\WEB-INF\classes
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\database.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\databaseLocal.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\efrit-security.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\efrit.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\efrit_logback.xml
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\ldap.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\logback.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\logback.xml
[INFO] Context path = /
[INFO] Tmp directory = C:\DEV\RTCworkspace\cct\cct-webapp\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = file:/C:/DEV/RTCworkspace/cct/cct-webapp/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = C:\DEV\RTCworkspace\cct\cct-webapp\src\main\webapp
[INFO] Starting jetty 7.1.6.v20100715 ...2012-07-04 11:16:56.349:INFO::jetty-7.1.6.v20100715

所以他说,他看到我的配置文件,但他无法阅读。

2 个答案:

答案 0 :(得分:0)

尝试设置:

<directory>configuration/local/</directory>

要:

<directory>${basedir}/configuration/local</directory>

答案 1 :(得分:0)

我尝试先前的答案,但它不起作用。 事实上,我发现了这个问题。一个profil隐藏一个加载此文件的bean。我有个人资料,而且运作良好。 这对春季3.1迁移有影响。