【问题标题】:Unable to load external spring config files with jetty maven plugin无法使用 jetty maven 插件加载外部弹簧配置文件
【发布时间】:2012-07-04 18:46:55
【问题描述】:

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

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::Context JettyWebAppContext@29b829b8@29b829b8/,file:/C:/DEV/RTCworkspace/myapp/myapp-webapp/src/main/webapp/,file: 启动失败/C:/DEV/RTCworkspace/myapp/myapp-webapp/src/main/webapp/ 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

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

【问题讨论】:

  • DataSourceLocal 是从 加载的

标签: spring maven jetty


【解决方案1】:

尝试设置:

<directory>configuration/local/</directory>

收件人:

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

【讨论】:

  • J'ai essayé comme je le disais dans le message au dessus。 Finalement j'ai trouvé, ca venait d'une bean non loader car le profiles n'était pas définit.
  • 是的...好吧,尝试将&lt;scanTargetPattern&gt;&lt;extraClasspath/&gt; 中的&lt;directory/&gt; 都设置为指向${basedir}/configuration/local。另外,尝试使用-X 运行 Maven 并粘贴 Jetty 插件显示的部分。
  • 感谢您的帮助,我找到了问题所在。它也是 spring 3.1 配置文件,它隐藏了一个加载 conf 文件的 bean。我现在尝试使用 -x,因为我不知道这个选项。再次感谢
  • -X 将以调试模式运行 Maven,显示大量输出。它将为所有插件启用调试日志记录,您将能够(希望)发现原因。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-14
    • 1970-01-01
    • 2018-08-11
    • 2019-02-06
    • 2016-12-13
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    相关资源
    最近更新 更多