簡體   English   中英

Spring Boot Maven多個模塊

[英]Spring boot maven multiple module

我編寫了一個簡單的spring boot多個模塊。 父模塊具有兩個子模塊訪問權限和Web模塊。 我把所有模塊配置放在下面。 這個示例項目在一個模塊中時可以正常工作,但是當我將其放在多個模塊中時拋出此異常

更新:完整堆棧跟蹤

線程“主”中的異常java.lang.IllegalArgumentException:無效的參數語法:-= org.springframework.core.env.SimpleCommandLinePropertySource。(-在org.springframework.core.env.SimpleCommandLineArgsParser.parse(SimpleCommandLineArgsParser.java:75)在org.springframework.boot.Spring.SpringApplication.configurePropertySources(SpringApplication.java:443)在org.springframework.boot.SpringApplication.configureEnvironment(SpringApplication.java:414)在org.springframework.boot.SpringApplication.run的SimpleCommandLinePropertySource.java:87) (SpringApplication.java:284)(位於org.springframework.boot.SpringApplication.run(SpringApplication.java:961)位於org.springframework.boot.SpringApplication.run(SpringApplication.java:950)位於com.spring.controller.Application。主要(Application.java:21)

如果需要,我將提供有關樣品的更多信息。

父模塊:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>parent</name>
<groupId>com.spring</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <spring-boot.version>1.3.3.RELEASE</spring-boot.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<modules>
    <module>access</module>
    <module>web</module>
</modules>

訪問模塊配置是這個

<parent>
    <artifactId>parent</artifactId>
    <groupId>com.spring</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>access</artifactId>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-rest-core</artifactId>
        <version>2.2.1.RELEASE</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
        </plugin>
    </plugins>
</build>

和Web模塊的配置是這樣的:

 <parent>
    <artifactId>parent</artifactId>
    <groupId>com.spring</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>web</artifactId>
<dependencies>
    <dependency>
        <groupId>com.spring</groupId>
        <artifactId>access</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
</dependencies>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>com.spring.controller.Application</start-class>
    <java.version>1.8</java.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
        </plugin>
    </plugins>
</build>

應用程序類代碼為:

 @Configuration
 @ComponentScan("com.spring.controller")
 @EnableJpaRepositories
 @Import(RepositoryRestMvcConfiguration.class)
 @EnableAutoConfiguration
 @PropertySource("application.properties")
 public class Application {

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
 }
}

該異常表明您使用SpringApplication.run(...)方法錯過了。 看來您正在傳遞-=作為參數。

查看Spring Boot指南的用法,或給我們您的代碼片段。

https://spring.io/guides/gs/spring-boot/

編輯1:

問題來自運行配置的參數。

在args中找到的參數不正確。 --=不可接受。

暫無
暫無

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

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