org.springframework.beans.factory.BeanCreationException:创建名称为(...)的bean时出错,无法自省类

时间:2018-09-04 15:15:50

标签: java eclipse maven spring-boot wildfly

我正在尝试在WildFly服务器上部署Spring Boot应用程序。

我的应用程序由3个子项目组成:dao(jar),metier(jar)和web(war)。 Web取决于等级,而等级取决于dao。

使用Java,Spring Boot 2,Maven,Angular 6,我将应用程序(pom.xml文件)修改为部署在WildFly服务器上。

在适应WildFly服务器之前,我的应用程序可以在本地(Eclipse Tomcat和Angular本地服务器)上正常工作。

首先,我尝试通过以下命令在Web项目(war)上从终端maven进行全新安装:

mvn clean install --also-make

但是对metier和dao的依赖并不令人满意。

所以我为我的父项目创建了一个父pom.xml。

这是我的父pom.xml:

<?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>fr.hillsoft</groupId>
    <artifactId>ecommerce-projet</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<modules>
    <module>ecommerce-dao</module>
    <module>ecommerce-metier</module>
    <module>ecommerce-web</module>
</modules>

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

</project>

这是我的3个子项目的pom.xml文件:

电子商务岛:

<?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>fr.hillsoft</groupId> -->
    <artifactId>ecommerce-dao</artifactId>
 <!--   <version>0.0.1-SNAPSHOT</version> -->
    <packaging>jar</packaging>

    <name>ecommerce-dao</name>
    <description>e-commerce Hillsoft DAO</description>

    <parent>
        <groupId>fr.hillsoft</groupId>
        <artifactId>ecommerce-projet</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

<!--    <parent> -->
<!--        <groupId>org.springframework.boot</groupId> -->
<!--        <artifactId>spring-boot-starter-parent</artifactId> -->
<!--        <version>2.0.2.RELEASE</version> -->
<!--        <relativePath/> lookup parent from repository -->
<!--    </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>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </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>
    </dependencies>

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

</project>

电子商务等级:

<?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>fr.hillsoft</groupId> -->
    <artifactId>ecommerce-metier</artifactId>
<!--    <version>0.0.1-SNAPSHOT</version> -->
    <packaging>jar</packaging>

    <name>ecommerce-metier</name>
    <description>e-commerce Hillsoft Métier</description>

    <parent>
        <groupId>fr.hillsoft</groupId>
        <artifactId>ecommerce-projet</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <!--    <parent> -->
    <!--        <groupId>org.springframework.boot</groupId> -->
    <!--        <artifactId>spring-boot-starter-parent</artifactId> -->
    <!--        <version>2.0.3.RELEASE</version> -->
    <!--        <relativePath/> lookup parent from repository -->
    <!--    </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>

    <dependencies>
        <dependency>
            <groupId>fr.hillsoft</groupId>
            <artifactId>ecommerce-dao</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </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-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </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>

    </dependencies>

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

</project>

电子商务网站:

<?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>fr.hillsoft</groupId> -->
    <artifactId>ecommerce-web</artifactId>
<!--    <version>0.0.1-SNAPSHOT</version> -->
    <packaging>war</packaging>

    <name>ecommerce-web</name>
    <description>e-commerce Hillsoft Web</description>

<parent>
    <groupId>fr.hillsoft</groupId>
    <artifactId>ecommerce-projet</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<!--    <parent> -->
<!--        <groupId>org.springframework.boot</groupId> -->
<!--        <artifactId>spring-boot-starter-parent</artifactId> -->
<!--        <version>2.0.2.RELEASE</version> -->
<!--        <relativePath/> lookup parent from repository -->
<!--    </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>

    <dependencies>
        <dependency>
            <groupId>fr.hillsoft</groupId>
            <artifactId>ecommerce-metier</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </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-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.wildfly.core/wildfly-server -->
        <dependency>
            <groupId>org.wildfly.core</groupId>
            <artifactId>wildfly-server</artifactId>
            <version>5.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.0</version>
        </dependency>

    </dependencies>

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

</project>

但是问题仍然存在。当我尝试从终端进行干净安装父项目时,会发生此错误:

package does not exist [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Consultat Hillsoft/workingset/workspace-ecommerce/ecommerce-projet/ecommerce-metier/src/main/java/fr/hillsoft/metier/impl/InternauteImpl.java:[11,25] package fr.hillsoft.model does not exist

[INFO] 100 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] ecommerce-projet 0.0.1-SNAPSHOT .................... SUCCESS [  1.986 s]
[INFO] ecommerce-dao ...................................... SUCCESS [ 18.025 s]
[INFO] ecommerce-metier ................................... FAILURE [  1.687 s]
[INFO] ecommerce-web 0.0.1-SNAPSHOT ....................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.369 s
[INFO] Finished at: 2018-08-31T14:17:18+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project ecommerce-metier: Compilation failure: Compilation failure:

[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :ecommerce-metier

在寻找解决方案时,当我使用Eclipse时,我尝试了Web子项目中“运行方式”条目中的“ Maven构建…”,目标是“全新安装”,“跳过测试”和“解决工作区”文物”。

我将从目标存储库创建的WAR文件复制到wildfly独立部署存储库中。

当我尝试使用standalone.sh run在WildFly服务器上部署项目时发生此错误:

这是列出错误的关键行:

11:51:35,702 ERROR [org.springframework.boot.SpringApplication] (ServerService Thread Pool -- 66) Application run failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountRestController': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module "deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main" from Service Module Loader]

Caused by: java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module "deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main" from Service Module Loader]

Caused by: java.lang.NoClassDefFoundError: fr/hillsoft/model/MyUser

Caused by: java.lang.ClassNotFoundException: fr.hillsoft.model.MyUser from [Module "deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main" from Service Module Loader]

11:51:35,704 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 66) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host."/ecommerce-web-0.0.1-SNAPSHOT": org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host."/ecommerce-web-0.0.1-SNAPSHOT": java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountRestController': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module "deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main" from Service Module Loader]

Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountRestController': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module "deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main" from Service Module Loader]

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountRestController': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module "deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main" from Service Module Loader]

Caused by: java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module "deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main" from Service Module Loader]

Caused by: java.lang.NoClassDefFoundError: fr/hillsoft/model/MyUser

Caused by: java.lang.ClassNotFoundException: fr.hillsoft.model.MyUser from [Module "deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main" from Service Module Loader]

11:51:35,710 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "ecommerce-web-0.0.1-SNAPSHOT.war")]) - failure description: {
    "WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host.\"/ecommerce-web-0.0.1-SNAPSHOT\"" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host.\"/ecommerce-web-0.0.1-SNAPSHOT\": java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountRestController': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module \"deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main\" from Service Module Loader]
    Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountRestController': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module \"deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main\" from Service Module Loader]
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountRestController': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module \"deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main\" from Service Module Loader]
    Caused by: java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module \"deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main\" from Service Module Loader]
    Caused by: java.lang.NoClassDefFoundError: fr/hillsoft/model/MyUser
    Caused by: java.lang.ClassNotFoundException: fr.hillsoft.model.MyUser from [Module \"deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main\" from Service Module Loader]"},
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host.\"/ecommerce-web-0.0.1-SNAPSHOT\""],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => undefined
}
11:51:35,769 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "ecommerce-web-0.0.1-SNAPSHOT.war" (runtime-name : "ecommerce-web-0.0.1-SNAPSHOT.war")
11:51:35,772 INFO  [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host."/ecommerce-web-0.0.1-SNAPSHOT": org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host."/ecommerce-web-0.0.1-SNAPSHOT": java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountRestController': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [fr.hillsoft.controller.AccountRestController] from ClassLoader [ModuleClassLoader for Module "deployment.ecommerce-web-0.0.1-SNAPSHOT.war:main" from Service Module Loader]

11:51:35,883 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started (with errors) in 11384ms - Started 516 of 768 services (2 services failed or missing dependencies, 405 services are lazy, passive or on-demand)
11:51:35,907 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0019: Stopped Driver service with driver-name = ecommerce-web-0.0.1-SNAPSHOT.war_org.postgresql.Driver_42_2
11:51:35,960 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0028: Stopped deployment ecommerce-web-0.0.1-SNAPSHOT.war (runtime-name: ecommerce-web-0.0.1-SNAPSHOT.war) in 59ms

WFLYCTL0186:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host."/ecommerce-web-0.0.1-SNAPSHOT"

这是MyUser.java的第一行:

package fr.hillsoft.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Version;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;

@Entity
public class MyUser {
    private Long id;

这是AccountRestController.java的第一行:

package fr.hillsoft.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import fr.hillsoft.metier.AccountService;
import fr.hillsoft.model.MyUser;

@RestController
public class AccountRestController {

    @Autowired
    private AccountService accountService;

    @PostMapping("/register")
    public MyUser register(@RequestBody RegisterForm registerForm) {

所有尝试可能都是由于相同的原因,是由于Maven依赖关系造成的吗?如何解决?

0 个答案:

没有答案