首页 > 解决方案 > 未找到 Spring Boot 控制器

问题描述

在我的 Spring Boot 应用程序中,我向项目中添加了一个新模块。

主 pom 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.apptizer.crm</groupId>
<artifactId>apptizer-admin-api</artifactId>
<version>0.0.2-SNAPSHOT</version>
<modules>
    <module>crm-service</module>
    <module>report-service</module>
</modules>
<packaging>pom</packaging>

<name>sample-admin-api</name>
<description>Demo project for Spring Boot</description>

<!--<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath /> &lt;!&ndash; lookup parent from repository &ndash;&gt;
</parent>-->

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.0.0.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>



<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.2</version>
            <configuration>
                <autoVersionSubmodules>true</autoVersionSubmodules>
                <tagNameFormat>@{project.version}</tagNameFormat>
            </configuration>
        </plugin>

      </plugins>
   </build>
</project>

现有的模块 pom 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
    <artifactId>sample-admin-api</artifactId>
    <groupId>io.sample.crm</groupId>
    <version>0.0.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>crm-service</artifactId>

<properties>
    <wrapper.location>${project.build.directory}/generated-resources/appassembler/jsw/sample-admin-api</wrapper.location>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>spring-libs-release</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/conf</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.basedir}/src/main/resources</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/*.yml</exclude>
                    <exclude>**/*.txt</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <version>1.10</version>
            <executions>
                <execution>
                    <id>generate-jsw-scripts</id>
                    <phase>package</phase>
                    <goals>
                        <goal>generate-daemons</goal>
                    </goals>
                    <configuration>
                        <repositoryLayout>flat</repositoryLayout>
                        <configurationDirectory>conf</configurationDirectory>
                        <daemons>
                            <daemon>
                                <id>apptizer-admin-api</id>
                                <wrapperMainClass>org.tanukisoftware.wrapper.WrapperSimpleApp</wrapperMainClass>
                                <mainClass>io.apptizer.crm.apptizercrmservice.App</mainClass>
                                <commandLineArguments>
                                    <commandLineArgument>start</commandLineArgument>
                                </commandLineArguments>
                                <platforms>
                                    <platform>jsw</platform>
                                </platforms>
                                <generatorConfigurations>
                                    <generatorConfiguration>
                                        <generator>jsw</generator>
                                        <configuration>
                                            <property>
                                                <name>wrapper.java.additional.1</name>
                                                <value>-Xloggc:logs/gclog</value>
                                            </property>
                                            <property>
                                                <name>wrapper.java.additional.2</name>
                                                <value>-XX:MaxDirectMemorySize=256M</value>
                                            </property>
                                            <property>
                                                <name>configuration.directory.in.classpath.first</name>
                                                <value>conf</value>
                                            </property>
                                            <property>
                                                <name>set.default.REPO_DIR</name>
                                                <value>lib</value>
                                            </property>
                                            <property>
                                                <name>wrapper.logfile</name>
                                                <value>logs/wrapper.log</value>
                                            </property>
                                        </configuration>
                                        <includes>
                                            <include>linux-x86-32</include>
                                            <include>linux-x86-64</include>
                                        </includes>
                                    </generatorConfiguration>
                                </generatorConfigurations>
                            </daemon>
                        </daemons>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <id>make-log-dir</id>
                    <phase>package</phase>
                    <configuration>
                        <tasks>
                            <mkdir dir="${wrapper.location}/logs" />
                            <copy todir="${wrapper.location}/conf">
                                <fileset dir="target/conf" />
                            </copy>
                            <chmod dir="${wrapper.location}/bin" includes="**/*" perm="0755" />
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
                <descriptor>src/assembly/dep.xml</descriptor>
                <finalName>apptizer-admin-api</finalName>
            </configuration>
            <executions>
                <execution>
                    <id>create-archive</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>


      </plugins>
   </build>
</project>

新增模块的 pom 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
    <artifactId>sample-admin-api</artifactId>
    <groupId>io.sample.crm</groupId>
    <version>0.0.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>report-service</artifactId>

<dependencies>
   // dependencies
 </dependencies>

</project>

所以之前生成了一个包装器。仍在crm-service映射模块中的控制器,但未映射新模块report-service中的控制器。我用一个工作映射路径替换了新控制器,这也不起作用。所以我认为这是构建文件中的错误。想法受到赞赏。

标签: mavenspring-bootmodulemapping

解决方案


得到了解决方案。如果控制器与主类位于单独的模块中,则只需向主类添加组件扫描,指向包含控制器的包。


推荐阅读