簡體   English   中英

無法使用maven過濾應用程序上下文從eclipse運行服務器

[英]Cannot run server from eclipse with maven filtering application context

我正在使用基於Eclipse的Spring Tool Suite和我的webapp以及Maven Filtering將數據庫憑據注入我的根上下文。

我的pom.xml包含以下內容:

<profiles>
    <profile>
        <id>debug</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <environment.type>debug</environment.type>

            <db.driver>com.mysql.jdbc.Driver</db.driver>
            <db.url>jdbc:mysql://xxx:3306/xxxxx</db.url>
            <db.username>xxxxxx</db.username>
            <db.password>xxxxxx</db.password>

            <tomcat.server>xxxxx</tomcat.server>
            <tomcat.path>/xxxxx</tomcat.path>
            <tomcat.url>http://xxx:8080/manager/text</tomcat.url>
            <tomcat.username>xxx</tomcat.username>
            <tomcat.password>xxx</tomcat.password>
        </properties>
    </profile>
</profiles>
...
<build>
        <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <webResources>
                    <resource>
                        <filtering>true</filtering>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <targetPath>WEB-INF</targetPath>
                        <includes>
                            <include>**/root-context.xml</include>
                        </includes>
                    </resource>
                </webResources>
            </configuration>
    </plugin>
</plugins>
</build>

雖然我的root-context.xml包含以下內容:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="${db.driver}" />
    <property name="jdbcUrl" value="${db.url}" />
    <property name="user" value="${db.username}" />
    <property name="password" value="${db.password}" />
    <property name="maxIdleTime" value="60" />
    <property name="idleConnectionTestPeriod" value="55" />
</bean>

當我部署到Tomcat時,我沒有遇到任何問題,同樣,當我使用Maven構建它時,我的目標文件夾包含已過濾的root-context.xml。

但是,當我嘗試使用“Run on Server ...”從Eclipse運行此webapp時,我收到以下錯誤:

WARN : com.mchange.v2.c3p0.DriverManagerDataSource - Could not load driverClass ${db.driver}
java.lang.ClassNotFoundException: ${db.driver}

似乎被復制的root-context.xml是未過濾的。 有沒有辦法解決這個問題?

在通過其他stackoverflow問題/答案進行一些挖掘之后,答案是在Web資源過濾中使用Maven war插件在帶有m2e的Eclipse中不起作用

如果將root-context.xml移動到src / main / resources目錄,它將包含在eclipse目標文件夾中並正確運行。

附加的pom.xml文件,使其全部工作。 不要忘記為測試過濾測試資源文件夾!

    <build>
    ....
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </testResource>
    </testResources>
    ....
    </build>

這就是我必須要做的事情,maven-war-plugin不需要額外的配置,我鏈接的另一個stackoverflow問題表明你需要。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM