简体   繁体   中英

Failed to execute goal deploy

I'm using JBOSS EAP-7.3.0 Java 9 in IntelliJ the remaining classes which are displayed in the error are created by default. So will just focus on the class MessageRepository .

The commands mvn clean and mvn install run successfully but mvn wildfly:deploy yields the following error:

Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:3.0.2.Final:deploy (default-cli) on project message_rest_servicesss: Failed to execute goal deploy: {"WFLYCTL006
    2: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"message_rest_servicesss-1.
    0-SNAPSHOT.war\".WeldStartService" => "Failed to start service
    [ERROR]     Caused by: org.jboss.weld.exceptions.DeploymentException: Exception List with 8 exceptions:
    [ERROR] Exception 0 :
    [ERROR] org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type EntityManager with qualifiers @Default
    [ERROR]   at injection point [BackedAnnotatedField] @Inject private org.example.entity.repository.MessageRepository.entityManager
    [ERROR]   at org.example.entity.repository.MessageRepository.entityManager(MessageRepository.java:0)
    [ERROR]
    [ERROR]         at org.jboss.weld.core@3.1.2.Final-redhat-00001//org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:378)
    [ERROR]         at org.jboss.weld.core@3.1.2.Final-redhat-00001//org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290)
    [ERROR]         at org.jboss.weld.core@3.1.2.Final-redhat-00001//org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:143)
    [ERROR]         at org.jboss.weld.core@3.1.2.Final-redhat-00001//org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:164)
    [ERROR]         at org.jboss.weld.core@3.1.2.Final-redhat-00001//org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:526)
    [ERROR]         at org.jboss.weld.core@3.1.2.Final-redhat-00001//org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:64)
    [ERROR]         at org.jboss.weld.core@3.1.2.Final-redhat-00001//org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:62)
    [ERROR]         at org.jboss.weld.core@3.1.2.Final-redhat-00001//org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
    [ERROR]         at org.jboss.weld.core@3.1.2.Final-redhat-00001//org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
    [ERROR]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    [ERROR]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    [ERROR]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    [ERROR]         at java.base/java.lang.Thread.run(Thread.java:844)
    [ERROR]         at org.jboss.threads@2.3.3.Final-redhat-00001//org.jboss.threads.JBossThread.run(JBossThread.java:485)

MessageRepository :

package org.example.entity.repository;


import org.example.entity.Message;


import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import java.util.List;
import java.util.logging.Logger;

@ApplicationScoped
public class MessageRepository {

    @Inject
    private Logger logger;

    @Inject
    private EntityManager entityManager;

    public Message getById(long id){
        logger.info("Get message by id: " + id);
        return entityManager.find(Message.class,id);
    }

    public List<Message> getAll(){
        CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
        CriteriaQuery<Message> criteriaQuery = criteriaBuilder.createQuery(Message.class);
        return entityManager.createQuery(criteriaQuery).getResultList();
    }

}

pom.xml :

<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>org.example</groupId>
    <artifactId>message_rest_servicesss</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>message_rest_servicesss</name>


    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>8.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>compile</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-endorsed-api</artifactId>
            <version>7.0</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <source>9</source>
                    <target>9</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>3.0.2.Final</version>
                <configuration>
                    <hostname>localhost</hostname>
                    <port>9990</port>
                    <username>****</username>
                    <password>*******</password>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
   
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.3.0</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>

My Project structure looks like this:

PROJECT_STRUCTURE

How can I fix this error?

By default a EntityManager is not injectable. You need to create a producer if you want to inject an EntityManager . Something like the following.

public class Resources {

    @Produces
    @PersistenceContext
    private EntityManager entityManager;

}

Your other option is to not use @Inject and use @PersistenceContext instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM