tomcat7-maven-plugin忽略server.xml中的域

时间:2014-02-10 13:15:57

标签: maven tomcat7 integration-testing server.xml

我有一个用于tomcat 7的Java webapp,它使用H2数据库进行数据以及用户身份验证。 当我在独立的Tomcat上部署webapp时,一切正常。

现在我想用maven运行集成测试。我使用tomcat7-maven-plugin 2.1版 当我运行集成测试时,tomcat(嵌入式)只使用tomcat-users.xml。 我已将server.xml放入src / main / tomcatconf中,并将其正确复制到target / tomcat / conf中。

我在server.xml中的领域定义

<Realm className="org.apache.catalina.realm.JDBCRealm"
        driverName="org.h2.Driver"
        connectionURL="jdbc:h2:DB/db;USER=user;PASSWORD=password;AUTO_SERVER=TRUE;"
        userTable="userAuth" userNameCol="username" userCredCol="userpass"
        userRoleTable="userAuth" roleNameCol="groupname" digest="SHA-512"/>

我的pom.xml

     <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <argLine>${failsafe.argLine}</argLine>
                <fork>true</fork>
                <path>/</path>

                <contextFile>${project.build.directory}/ROOT/META-INF/context.xml</contextFile>

                <systemProperties>
                    <JAVA_OPTS>-Xms128m -Xmx256m -XX:PermSize=512m -XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled</JAVA_OPTS>

                </systemProperties>

            </configuration>
            <executions>
                <execution>
                    <id>tomcat-run</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run-war-only</goal>
                    </goals>
                    <configuration>

                        <path>/</path>
                        <serverXml>src/main/tomcatconf/server.xml</serverXml>

                        <port>8080</port>
                    </configuration>
                </execution>

                <execution>
                    <id>tomcat-shutdown</id>

                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>shutdown</goal>
                    </goals>

                </execution>


            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.h2database</groupId>
                    <artifactId>h2</artifactId>
                    <version>1.3.173</version>
                </dependency>
            </dependencies>



        </plugin>

我尝试了不同的方法,我在互联网上(以及Apache网站上),但没有任何效果。 当我添加一个包含我的测试用户的tomcat-users.xml时,测试工作。

更新

这里是日志

Running war on http://localhost:8080/
Creating Tomcat server configuration at D:\project\target\tomcat
Coping additional tomcat config files
 copy server.xml
 copy _tomcat-users.xml
setting SystemProperties:
 JAVA_OPTS=-Xms128m -Xmx256m -XX:PermSize=512m -XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled
create webapp with contextPath: 
Feb 10, 2014 2:44:40 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Feb 10, 2014 2:44:40 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Feb 10, 2014 2:44:40 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.37
Feb 10, 2014 2:44:42 PM org.jboss.weld.bootstrap.WeldBootstrap <clinit>
INFO: WELD-000900 2.0.3 (Final)
Feb 10, 2014 2:44:42 PM org.jboss.weld.bootstrap.WeldBootstrap startContainer
INFO: WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Feb 10, 2014 2:44:43 PM org.jboss.weld.environment.tomcat7.Tomcat7Container initialize
INFO: Tomcat 7 detected, CDI injection will be available in Servlets and Filters. Injection into Listeners is not supported
Feb 10, 2014 2:44:43 PM org.jboss.weld.interceptor.util.InterceptionTypeRegistry <clinit>
WARNING: Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
Feb 10, 2014 2:44:43 PM org.jboss.weld.interceptor.util.InterceptionTypeRegistry <clinit>
WARNING: Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
Feb 10, 2014 2:44:43 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]

--- jacoco-maven-plugin:0.6.3.201306030806:prepare-agent (pre-integration-test) @ ILS_webapp 

--- exec-maven-plugin:1.2.1:exec (gen-mvnopts-bat) @ ILS_webapp ---
--- maven-resources-plugin:2.6:copy-resources (copy-resources) @ ILS_webapp ---
Using 'UTF-8' encoding to copy filtered resources.
Copying 6 resources

我重命名了tomcat-users.xml th _tomcat-users.xml以避免将此文件用作域。 webapps部署得很好。只有身份验证不起作用。

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <listener>
        <listener-class>
            org.jboss.weld.environment.servlet.Listener
        </listener-class>
    </listener>
    <resource-env-ref>
        <resource-env-ref-name>BeanManager</resource-env-ref-name>
        <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
    </resource-env-ref>
    <security-constraint>
        <web-resource-collection>
            <url-pattern>/error/*</url-pattern>
<!--            <url-pattern>/css/*</url-pattern>-->
            <url-pattern>/js/*</url-pattern>
            <url-pattern>/img/*</url-pattern>
            <url-pattern>/api/*</url-pattern>
            <url-pattern>/resources/*</url-pattern>
            <url-pattern>/favicon.ico</url-pattern>
        </web-resource-collection>
    </security-constraint>
    <security-constraint>
        <display-name>secure</display-name>
        <web-resource-collection>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>ADMIN</role-name>
            <role-name>USER</role-name>
        </auth-constraint>
    </security-constraint>

    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>myRealm</realm-name>
        <form-login-config>
            <form-login-page>/index.html</form-login-page>
            <form-error-page>/index_failed.html</form-error-page>
        </form-login-config>
    </login-config>


    <security-role>
        <role-name>ADMIN</role-name>
    </security-role>
    <security-role>
        <role-name>USER</role-name>
    </security-role>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

0 个答案:

没有答案