我正在使用 Helidon MP 开发微服务应用程序。到目前为止我的经历非常棒。但我最终寻找 Helidon MP 的启动/关闭挂钩。我试图通过搜索和 Helidon Javadoc 来查找。但我找不到任何有用的东西。
Helidon MP / Microprofile 是否提供此类功能?
我正在尝试在我拥有的另一项服务上执行请求。我用来创建应用程序的指南是:
我收到如下错误:
org.jboss.resteasy.spi.UnhandledException: java.lang.RuntimeException: Error injecting com.easy.ecomm.core.product.ProductClient com.easy.ecomm.core.cart.CartService.productClient
org.eclipse.microprofile.rest.client.RestClientDefinitionException: Parameters and variables don't match on interface com.easy.ecomm.core.product.ProductClient::findProductById
Run Code Online (Sandbox Code Playgroud)
这是 ProductClient 类
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@Path("products")
@RegisterRestClient(configKey = "products-api")
public interface ProductClient {
@GET
@Path("{id}")
Product findProductById(String id);
}
Run Code Online (Sandbox Code Playgroud)
这是服务层:
import org.eclipse.microprofile.rest.client.inject.RestClient;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
@ApplicationScoped
public class CartService {
@Inject
@RestClient
ProductClient productClient;
public void addItem(String cartId, String productId, Integer amount){
// Code to find the cart on a …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 OpenWebBeans 与 Tomcat 10 一起使用。我已按照此链接中给出的步骤进行操作。
当我使用 Weld 时,效果很好。但是当我使用 OpenWebBeans 时,出现以下错误。
SEVERE: Error configuring application listener of class [org.apache.webbeans.servlet.WebBeansConfigurationListener]
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener ...
Run Code Online (Sandbox Code Playgroud)
我的pom文件如下
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>minimal</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.faces</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-jsf</artifactId>
<version>2.0.21</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.1.Final</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId> …Run Code Online (Sandbox Code Playgroud) 我试图以编程方式选择 bean,但 quarkus 不会注入 bean 并引发异常。不支持吗?
public enum ReportType {
ONE,
TWO
}
Run Code Online (Sandbox Code Playgroud)
@Qualifier
@Retention(RUNTIME)
@Target({METHOD, PARAMETER, FIELD, TYPE})
@Documented
public @interface Report {
ReportType value();
public static final class Literal extends AnnotationLiteral<Report> implements Report {
private final ReportType value;
public static Literal of(ReportType value) {
return new Literal(value);
}
private Literal(ReportType value) {
this.value = value;
}
public ReportType value() {
return value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
public interface CommonnInterface {
void call();
}
Run Code Online (Sandbox Code Playgroud)
@Report(value = ReportType.ONE)
public class ReportOneBusiness …Run Code Online (Sandbox Code Playgroud) 请求有关此拦截器注释的更多信息。为什么拦截器注解叫@AroundInvoke而不是@BeforeInvoke?
例如,我可以在操作 API 之前调用访问验证吗?如何保证在实际调用方法之前完成访问验证?VM 或 CDI 实现是否会执行某些操作,但不会阻止实际调用,而是并行执行此拦截器?
如果我使用Google Guice AOP 方法拦截器,我确信访问验证失败将确定方法调用是否开始。我如何确保雅加达 CDI 也会采取类似的行为?
无法在规范中找到此信息
可以在这里找到相关问题。但上述具体问题仍未得到解答。
我已经阅读了一些关于JEE6上Observer模式实现的博客文章,还有什么困扰我......我找不到任何信息,所以我问那里......
我发现了以下例子:
@Stateless
[...]
public class ParisJugService {
@Inject
Event event;
public void helloParis(){
System.out.println("Hello Paris");
event.fire("hello Paris invoked!");
}
}
@Stateless
public class EventReceiver {
public void onHelloParis(@Observes String message){
System.out.println("----------- " + message);
}
}
Run Code Online (Sandbox Code Playgroud)
和
public class MyEvent {
String data;
Date eventTime;
....
}
public class EventProducer {
@Inject @Any Event<MyEvent> event;
public void doSomething() {
MyEvent e=new MyEvent();
e.data="This is a test event";
e.eventTime=new Date();
event.fire(e);
}
}
public class EventConsumer {
public void afterMyEvent(@Observes …Run Code Online (Sandbox Code Playgroud) 我在tomcat上遇到了CDI问题.这是我的代码的一些相关部分:
public class JPAUtil {
private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("unit");
@Produces @RequestScoped
public static EntityManager getEntityManager() {
return emf.createEntityManager();
}
public void close(@Disposes EntityManager em) {
em.close();
}
}
Run Code Online (Sandbox Code Playgroud)
我的DAO课程:
public class DAO<T> implements Serializable{
private final Class<T> classe;
@Inject
protected EntityManager em;
public DAO(Class<T> classe) {
this.classe = classe;
}
}
Run Code Online (Sandbox Code Playgroud)
和一个儿童班:
public class UserDao extends DAO<User> implements Serializable{
public UserDao() {
super(User.class);
}
}
Run Code Online (Sandbox Code Playgroud)
由于Generics,我使用DAO类的生产者:
public class DAOFactory {
@Produces
@SuppressWarnings({ "rawtypes", "unchecked" })
public DAO createDAO(InjectionPoint …Run Code Online (Sandbox Code Playgroud) 当我@Named用在Glassfish服务器上部署Web应用程序时使用的CDI(JSR299)注释对IntelliJ进行管理时,IntelliJ似乎无法识别我的JSF2托管Bean 。
@Named("userBean")
@SessionScoped
public class UserBean implements Serializable {
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Run Code Online (Sandbox Code Playgroud)
在EL表达式(例如#{userBean.name})中使用bean时,我没有任何自动完成的功能。而且,当我在IntelliJ中打开JSF选项卡时,没有列出托管豆。当我使用@ManagedBean注释时,我会自动完成,并且我的bean列在“ JSF”选项卡中。我是否需要配置某些东西或如何使其正常工作?
IE:com.adms.fcl3.entity.User无法强制转换为com.adms.fcl3.entity.User
自从将项目从EJB/ManagedBeans迁移到CDI以来,我开始遇到这种错误,所以我的猜测是AoP/Injection混乱了类.
但我没有证据证明这一点.也没有解决方案.
负责的代码:
public User getByLoginPasswdValid(String login, String passwd) {
TypedQuery<User> q = em.createNamedQuery("User.findByLoginPasswdValid", User.class);
q.setParameter("login", login);
q.setParameter("passwd", passwd);
List<User> results = q.getResultList();
if (results.isEmpty()) {
return null;
}
return results.get(0);
}
Run Code Online (Sandbox Code Playgroud)
失败了return results.get(0);.Debuger向我确认该列表有效,具有User对象,具有适当的值等...
我试图在WildFly 8.1.0.Final上使用CDI运行Liquibase脚本,我收到此错误:
Unsatisfied dependencies for type ResourceAccessor with qualifiers @LiquibaseType
Run Code Online (Sandbox Code Playgroud)
我的POM有这些依赖:
<dependencies>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-cdi</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.mattbertolini</groupId>
<artifactId>liquibase-slf4j</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我的CDI Bean如下:
import javax.annotation.Resource;
import javax.enterprise.inject.Produces;
import javax.sql.DataSource;
import liquibase.integration.cdi.CDILiquibaseConfig;
import liquibase.integration.cdi.annotations.LiquibaseType;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.ResourceAccessor;
public class LiquibaseStarter {
@Produces
@LiquibaseType
public CDILiquibaseConfig createConfig() {
CDILiquibaseConfig config = new CDILiquibaseConfig();
config.setChangeLog("liquibase/parser/core/xml/simpleChangeLog.xml");
return config;
}
@Resource(name="java:jboss/datasources/ExampleDS")
private DataSource ds;
@Produces
@LiquibaseType
public DataSource createDataSource() {
return ds;
}
@Produces
@LiquibaseType
public ResourceAccessor …Run Code Online (Sandbox Code Playgroud) cdi ×10
java ×5
jpa ×2
autocomplete ×1
ejb ×1
ejb-3.1 ×1
helidon ×1
interceptor ×1
jakarta-ee ×1
java-ee-6 ×1
java-ee-7 ×1
javabeans ×1
jboss-weld ×1
jsf ×1
jsf-2 ×1
liquibase ×1
microprofile ×1
openwebbeans ×1
quarkus ×1
rest ×1
tomcat ×1
tomcat10 ×1
wildfly-8 ×1