[英]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.我在 IntelliJ 中使用 JBOSS EAP-7.3.0 Java 9 其余显示在错误中的类是默认创建的。 So will just focus on the class
MessageRepository
.所以只关注 class
MessageRepository
。
The commands mvn clean
and mvn install
run successfully but mvn wildfly:deploy
yields the following error:命令
mvn clean
和mvn install
成功运行,但mvn wildfly:deploy
产生以下错误:
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
: 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
: 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:我的项目结构如下所示:
How can I fix this error?我该如何解决这个错误?
By default a EntityManager
is not injectable.默认情况下,
EntityManager
是不可注入的。 You need to create a producer if you want to inject an EntityManager
.如果要注入
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.您的另一个选择是不使用
@Inject
而使用@PersistenceContext
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.