1

在 Spring3+Maven+Tomcat6 Web 项目中..

我尝试在 REST api Controller 中使用相同的 RequestMapping。
因为..我需要不同用途的不同战争。

所以,我生成了同名控制器,但不同的包。
例如...
1. xxx.controller.agent.UserController
2. xxx.controller.console.UserController

在 pom.xml..
1. maven -> build(war:war) -> get console.war include xxx.controller.agent.UserController
2. 取消注释 testExcludes 中
的注释行并排除 3. 注释 testExcludes 中未注释的行并排除
4. maven -> 更新项目配置
5. maven -> build (war:war) -> get agent war include xxx.controller.console.UserController

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <testExcludes>
            <exclude>com/test/store/controller/agent/*.java</exclude>
            <exclude>com/test/rbac/controller/agent/*.java</exclude>
            <!-- <exclude>com/test/store/controller/console/*.java</exclude>
            <exclude>com/test/rbac/controller/console/*.java</exclude> -->
        </testExcludes>
        <excludes>
            <exclude>com/test/store/controller/agent/*Controller.java</exclude>
            <exclude>com/test/rbac/controller/agent/*Controller.java</exclude>                      
            <!-- <exclude>com/test/store/controller/console/*Controller.java</exclude>
            <exclude>com/test/rbac/controller/console/*Controller.java</exclude> -->
        </excludes>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>

但是,我不想为每个战争版本编辑 pom.xml。我尝试使用 Maven 配置文件元素构建每个战争文件。所以,我编辑了我的 pom.xml,如下所示..

<properties>
<exclude.console.store>com/test/store/controller/agent/**</exclude.console.store>
<exclude.console.rbac>com/test/rbac/controller/agent/**</exclude.console.rbac>
<exclude.agent.store>com/test/store/controller/console/**</exclude.agent.store>
<exclude.agent.rbac>com/test/rbac/controller/console/**</exclude.agent.rbac>
</properties>
...
<profiles>
    <profile>
        <id>console</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <packagingExcludes>
                            WEB-INF/classes/${exclude.console.store},
                            WEB-INF/classes/${exclude.console.rbac}
                        </packagingExcludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <testExcludes>
                            <exclude>${exclude.console.store}</exclude>
                            <exclude>${exclude.console.rbac}</exclude>                      
                        </testExcludes>
                        <excludes>
                            <exclude>${exclude.console.store}</exclude>
                            <exclude>${exclude.console.rbac}</exclude>                      
                        </excludes>
                        <source>1.6</source>
                        <target>1.6</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
            </plugins>
        </build>    
    </profile>

    <profile>
        <id>agent</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <packagingExcludes>
                            WEB-INF/classes/${exclude.agent.store},
                            WEB-INF/classes/${exclude.agent.rbac},
                            WEB-INF/classes/spring/task.xml
                        </packagingExcludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <testExcludes>
                            <exclude>${exclude.agent.store}</exclude>
                            <exclude>${exclude.agent.rbac}</exclude>                        
                        </testExcludes>
                        <excludes>
                            <exclude>${exclude.agent.store}</exclude>
                            <exclude>${exclude.agent.rbac}</exclude>                        
                        </excludes>
                        <source>1.6</source>
                        <target>1.6</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
            </plugins>
        </build>    
    </profile>
</profiles>

和 Maven 构建..(goal="package" 或 "compile war:war", profile="console" 或 "agent" 在每种情况下)
构建成功..(无编译错误)但战争异常。
我将war文件复制到tomcat webapp目录,并执行startup.bat文件。
在控制台日志中..发生了很多错误。
也许我认为 maven compile 有一些问题。
我解压了每个构建方法的war文件(使用配置文件和旧方法)。
但是,类文件的数量不同......

感谢您的帮助,非常感谢!

4

0 回答 0