简体   繁体   中英

How can I run both xml config driven and xml-less Spring webapps together with Maven?

I have a couple of webapps I'm trying to run up together using Maven tomcat7 plugin.

I have the first project which is an XML driven Spring application and another application I'm trying to run alongside it which is fetched as a war from our Maven repository.

When I enable (uncomment) the ... block the way attempts to start but I get errors about a bean within the project (that this pom belongs to) not being autowired in.

I suspect somehow the configs are confusing each other... is that possible when running like this?

Ultimately I think I'm going to end up running them as separate apps in different IDE windows, but would rather have them run together, by running 1 tomcat7:run target, from a single version control project.

ie localhost:8090/MainApp localhost:8090/Stubs

I hope that makes sense!

<build>
    <finalName>MainProjectApplication</finalName>
    <!-- this project is XML driven Spring 3 -->
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>

            <configuration>
                <port>8090</port>
                <path>/MainApp</path>
                <contextReloadable>true</contextReloadable>
                <contextFile>${project.basedir}/environment/localhost/context/mainApp.xml</contextFile>
                <webapps>
                    <webapp>
                        <!-- this is Spring4 xml-less config, not even web.xml -->
                        <contextPath>/stubs</contextPath>
                        <groupId>uk.my.package</groupId>
                        <artifactId>included-project</artifactId>
                        <version>1.1-SNAPSHOT</version>
                        <type>war</type>
                        <asWebapp>true</asWebapp>
                    </webapp>
                </webapps>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>${project.artifactId}</artifactId>
                    <version>${project.version}</version>
                    <classifier>localhost-config</classifier>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/localhost-config.xml</descriptor>
                </descriptors>
                <classifier>localhost-config</classifier>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <version>${maven-enforcer-plugin.version}</version>
            <executions>
                <execution>
                    <id>enforce-versions</id>
                    <goals>
                        <goal>enforce</goal>
                    </goals>
                    <configuration>
                        <rules>
                            <requireMavenVersion>
                                <version>[3.0.0,)</version>
                            </requireMavenVersion>
                        </rules>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <showDeprecation>true</showDeprecation>
            </configuration>
        </plugin>
    </plugins>
</build>

Turns out the componant scanning was setup to scan the same package names. ie. uk.me.organisation

I changed in respective config to: uk.me.organisation.mainapp and uk.me.organisation.stubs

Now there is no overlap they seem to play nicely together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM