Spring boot maven多个模块

时间:2016-03-26 15:17:12

标签: java spring maven spring-boot

我写了一个简单的spring boot多个模块。父模块有两个子模块访问和Web模块。我把所有模块配置放在下面。当这是一个模块时,这个示例项目正常工作,但当我把它放在多个模块中时抛出此异常

更新:完整堆栈跟踪

  

线程“main”中的异常java.lang.IllegalArgumentException:参数语法无效: - =       在org.springframework.core.env.SimpleCommandLineArgsParser.parse(SimpleCommandLineArgsParser.java:75)       在org.springframework.core.env.SimpleCommandLinePropertySource。(SimpleCommandLinePropertySource.java:87)       在org.springframework.boot.SpringApplication.configurePropertySources(SpringApplication.java:443)       在org.springframework.boot.SpringApplication.configureEnvironment(SpringApplication.java:414)       在org.springframework.boot.SpringApplication.run(SpringApplication.java:284)       在org.springframework.boot.SpringApplication.run(SpringApplication.java:961)       在org.springframework.boot.SpringApplication.run(SpringApplication.java:950)       在com.spring.controller.Application.main(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);
 }
}

1 个答案:

答案 0 :(得分:2)

该异常表明您未使用SpringApplication.run(...)方法。看起来你正在传递 - =作为参数。

查看Spring Boot指南了解它的用法或给我们您的代码片段。

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

编辑1:

问题来自运行配置的参数。

args中找到的参数不正确。 --=是不可接受的。