spring-boot - 在企业应用程序中部署 Spring Boot 模块 :TransactionManagementConfigurationSelector is not assignable to interface ImportSelector

标签 spring-boot dependency-injection maven-plugin multi-module enterprise-architecture

我有一个包含两个模块的 Maven 项目“企业应用程序”。第一个模块是一个 maven 标准 java 应用程序,包含域、dao 和业务层。第二个模块是“java web 应用程序”maven。这是到目前为止设置的配置:
- 标准的 java 应用程序模块:
主类

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

}

pom.xml
<parent>
        <groupId>com.nhit.dev</groupId>
        <artifactId>mobilepayment</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <groupId>com.nhit.dev</groupId>
    <artifactId>mobilepayment-dao</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>mobilepayment-dao</name>
    <description>Demo project for Spring Boot</description>

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

    <dependencies>
        <!-- Spring -->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>dom4j</groupId>
                    <artifactId>dom4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
                        <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- JBehave -->
        <dependency>
            <groupId>org.jbehave</groupId>
            <artifactId>jbehave-core</artifactId>
            <version>4.0.5</version>
        </dependency>
        <dependency>
            <groupId>org.jbehave</groupId>
            <artifactId>jbehave-spring</artifactId>
            <version>4.0.5</version>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Brixton.SR5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
                <classifier>exec</classifier>
            </configuration>
        </plugin>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build> 
</project>
  • java web 应用程序模块:
    主类

    @SpringBootApplication(排除 = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
    公共(public)类 MobilepaymentApplication 扩展 SpringBootServletInitializer{
    公共(public)静态无效主要(字符串[]参数){
    SpringApplication.run(MobilepaymentApplication.class, args);
    System.out.println("dan​​s le main");
            }
            @Override
            protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
                return application.sources(applicationClass);
            }
    
            private static Class<MobilepaymentApplication> applicationClass = MobilepaymentApplication.class;
        }
    

  • pom.xml
    <parent>
            <groupId>com.nhit.dev</groupId>
            <artifactId>mobilepayment</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
    
        <groupId>com.nhit.dev</groupId>
        <artifactId>mobilepayment-web</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>
    
        <name>mobilepayment-web</name>
    
        <properties>
            <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.apache.tomcat.embed</groupId>
                        <artifactId>tomcat-embed-core</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.apache.tomcat.embed</groupId>
                        <artifactId>tomcat-embed-websocket</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-frontend-jaxws</artifactId>
                <version>3.1.7</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-core</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-bindings-soap</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-bindings-xml</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http</artifactId>
                <version>3.1.7</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-core</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
            </dependency>
            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>mobilepayment-dao</artifactId>
                <version>${project.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-bindings-xml</artifactId>
                <version>3.1.7</version>
                <!--            <scope>provided</scope>-->
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-bindings-soap</artifactId>
                <version>3.1.7</version>
                <!--            <scope>provided</scope>-->
            </dependency>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-web-api</artifactId>
                <version>7.0</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>   
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    </plugins>
        </build>
    
    </project>
    

    -- 企业应用模块(.ear)
    pom.xml
    <parent>
            <artifactId>mobilepayment</artifactId>
            <groupId>com.nhit.dev</groupId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
        <groupId>com.nhit.dev</groupId>
        <artifactId>mobilepayment-ear</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>ear</packaging>
        <name>mobilepayment-ear</name>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
           <build>
            <plugins>
                <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>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>2.8</version>
                    <configuration>
                        <version>6</version>
                        <defaultLibBundleDir>lib</defaultLibBundleDir>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>com.nhit.dev</groupId>
                <artifactId>mobilepayment-dao</artifactId>
                <version>0.0.1-SNAPSHOT</version>
                <type>jar</type>
            </dependency>
            <dependency>
                <groupId>com.nhit.dev</groupId>
                <artifactId>mobilepayment-web</artifactId>
                <version>0.0.1-SNAPSHOT</version>
                <type>war</type>
            </dependency>
        </dependencies>
    </project>
    

    -- 多模块 Maven 项目:
    pom.xml
    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.4.1.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <groupId>com.nhit.dev</groupId>
        <artifactId>mobilepayment</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>pom</packaging>
        <name>mobilepayment</name>    
    
        <modules>
            <module>mobilepayment-dao</module>
            <module>mobilepayment-web</module>
            <module>mobilepayment-ear</module>
        </modules>
    
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
    
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>2.6</version>
                </plugin>
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>1.0.1.Final</version>
                </plugin>
            </plugins>
        </build>
    </project>
    

    当我通过单击运行从 netbeans 部署企业应用程序项目时,出现以下异常:
    Deploying C:\wildfly-10.0.0.Final\standalone\deployments\mobilepayment-ear-0.0.1-SNAPSHOT.ear
    {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./mobilepayment-web" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./mobilepayment-web: java.lang.RuntimeException: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$TransactionManagementConfiguration]; nested exception is java.lang.IllegalArgumentException: class org.springframework.transaction.annotation.TransactionManagementConfigurationSelector is not assignable to interface org.springframework.context.annotation.ImportSelector
        Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$TransactionManagementConfiguration]; nested exception is java.lang.IllegalArgumentException: class org.springframework.transaction.annotation.TransactionManagementConfigurationSelector is not assignable to interface org.springframework.context.annotation.ImportSelector
        Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$TransactionManagementConfiguration]; nested exception is java.lang.IllegalArgumentException: class org.springframework.transaction.annotation.TransactionManagementConfigurationSelector is not assignable to interface org.springframework.context.annotation.ImportSelector
        Caused by: java.lang.IllegalArgumentException: class org.springframework.transaction.annotation.TransactionManagementConfigurationSelector is not assignable to interface org.springframework.context.annotation.ImportSelector"}}
    

    最佳答案

    它已经很老了,但我刚刚遇到了同样的问题,我通过添加找到了解决方案

    @EnableAutoConfiguration(exclude = {TransactionAutoConfiguration.class}
    

    但我应用了它,因为我没有在我的应用程序中使用任何与交易相关的东西

    关于spring-boot - 在企业应用程序中部署 Spring Boot 模块 :TransactionManagementConfigurationSelector is not assignable to interface ImportSelector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40737075/

    相关文章:

    spring - Groovy:Lombok @NoArgsConstructor 不创建默认构造函数

    asp.net-mvc - SimpleInjector - 装饰器没有启动?

    mvvm - 数据源、存储库、 View 模型和 IoC 容器。真的需要存储库吗?

    design-patterns - 如何实践OOP设计的SOLID原则?

    java - mvn混淆器: Is there possible obfuscate dependency before copying

    spring-mvc - 访问 Spring Boot Zuul Service 路由的身份验证

    spring - java.lang.ClassCastException : javax. xml.bind.JAXBElement 无法转换为

    maven-2 - 未构建 Maven 子模块

    java - 如何获取 Maven 插件的当前执行情况?

    java - Azure Spring Boot - 获取登录用户的 OAuth 2.0 访问 token