weld

JPMS: --add-opens doesn't work for java.lang.reflect.InaccessibleObjectException

不想你离开。 提交于 2020-04-11 05:44:56
问题 I use Java 14 with Jetty 9.4 and Weld-servlet-shaded-3.1 and I get this exception: Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to module weld.servlet.shaded. According to answer here: https://stackoverflow.com/a/41265267/5057736 I tried to add --add-opens java.base/java.lang=ALL

Quarkus框架入门之二:依赖注入

 ̄綄美尐妖づ 提交于 2020-03-13 00:39:23
前言 Spring框架最开始被我熟知就是AOP和IOC,其中IOC在开发过程中更是被广泛使用,如果切换到一个新的框架没有了依赖注入和控制反转,那么可以说一夜回到解放前了。那么,Quarkus框架中有没有对应的功能呢? 当然也有,Quarkus基于CDI规范提供了依赖注入的相关功能,本文将进行简单介绍。 CDI-Contexts and Dependency Injection 简单介绍 CDI(Contexts and Dependency Injection),即上下文依赖注入,是J2EE6发布的一个标准规范,用于对上下文依赖注入的标准规范化,思想应该是来源于Spring的IOC,存在的年头已经挺久远。但是之前一直没怎么关注这个规范,都是用Spring Framework打天下。 以前以为只能在J2EE中使用,但是在写这篇文章的时候,发现在J2SE8.0已经可以使用CDI了,只需要明确引导CDI容器即可。 简单使用示例(J2SE) 以下以在一个简单的Java项目中使用weld实现依赖注入进行简单示例,依赖包如下: <dependency> <groupId>org.jboss.weld.se</groupId> <artifactId>weld-se-core</artifactId> <version>3.1.0.Final</version> </dependency> 首先

CDI/Weld unable to do constructor injection of RESTEasy resource

江枫思渺然 提交于 2020-02-21 14:06:04
问题 I'm trying to combine RESTEasy with Weld on AppEngine but having troubles to do constructor injection. I've added the RESTEasy CdiInjectorFactory context param and the Weld servlet listener. My RESTEasy application class looks like: public class MyApplication extends Application { @Override public Set<Class<?>> getClasses() { HashSet<Class<?>> classes = new HashSet<Class<?>>(); classes.add(CustomerResource.class); return classes; } } and the CustomerResource: @Path("/rest/app/customers")

CDI extension, altering processed type

ε祈祈猫儿з 提交于 2020-02-07 05:17:24
问题 Using Weld 1.1.13.Final in test with Arquillian.... Let's say I inject into a field something volatile. Something like a property subject to change that I want the bean owning the injection point to receive change events. Thought about creating a CDI extension. Caught ProcessAnnotatedType event and looking for all fields that have an custom annotation on field injection points: <T> void pat(@Observes ProcessAnnotatedType<T> event, BeanManager bm) { final AnnotatedType<T> target = event

How to write main() using CDI in Java EE?

时光总嘲笑我的痴心妄想 提交于 2020-01-14 04:24:34
问题 I have a no-client application that I wish to run. It will have no clients but it will make HTTP calls and act as client for other services. It would run for perhaps a few hours or days (but it will not require periodic runs -- just one-shot). I want to run it in a Java EE 7 container, because of the benefits of standard Context Dependency Injection (CD), and a standard JAX-RS client (new since Java EE 7). It is also nice to have services such as JMS, JPA. The question is how do I write /

Specifying different subclass implementations in CDI

丶灬走出姿态 提交于 2020-01-04 15:32:15
问题 I have two classes, A and B, which need to use a service. There are two services, S1 and S2. S2 extends S1. I wish to inject S1 into class A and S2 into class B. How can I accomplish this in CDI? public class S1 {} public class S2 extends S1 {} public class A { @Inject S1 service; //Ambigious? Could be S1 or S2? } public class B { @Inject S2 service; } 回答1: The @Typed annotation enables restricting bean types so that you can write: public class S1 {} @Typed(S2.class) public class S2 extends

Unable to resolve any beans for Type: xxx; Qualifiers: [@javax.enterprise.inject.Any()]

半城伤御伤魂 提交于 2020-01-04 02:57:11
问题 I have a LoginProvider interface: public interface LoginProvider { boolean login(String username, String password); } And 2 different implementations: public class LoginProvider1Impl implements LoginProvider { @Override public boolean login(String username, String password) { ... } } public class LoginProvider2Impl implements LoginProvider { @Override public boolean login(String username, String password) { ... } } Then a producer annotation: @Qualifier @Retention(RetentionPolicy.RUNTIME)

Get rid of org.jboss.weld.context.NonexistentConversationException, when a query-string parameter named cid is appended to the URL

和自甴很熟 提交于 2019-12-29 08:57:31
问题 Take a simple CDI (it could also be a JSF managed bean) bean as follows. import java.io.Serializable; import javax.inject.Named; import javax.faces.view.ViewScoped; @Named @ViewScoped public class TestManagedBean implements Serializable { private static final long serialVersionUID=1L; public TestManagedBean() {} } If this bean is accessed by an XHTML page with a query-string parameter named cid which is needed for a @ConversationScoped CDI managed bean (which may accidently/deliberately be

Bootstrap Weld in a Spring Boot environment

自古美人都是妖i 提交于 2019-12-25 12:55:25
问题 Does anyone know a way to bootstrap Weld in a Spring Boot Jar application with embedded Tomcat. I have tried to use org.jboss.weld.environment.servlet.Listener with import org.jboss.weld.environment.servlet.Listener; @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } @Bean public Listener weldListener() { return new Listener(); } } But I get the following error: java.lang.RuntimeException: WELD-ENV

CDI (Weld SE) not injecting inner dependencies when using Producer method

我的未来我决定 提交于 2019-12-25 08:30:14
问题 I'm using WELD SE on a standalone java project which seemed to work fine till I started using producers. The producer method works - the container uses it, but never injects the inner pdependencies of the produced bean. When I remove the producer, it works normally. I can't find the cause even after a long search on the spec and on Google. Example of a Producer: @ApplicationScoped public class LaminaValidadorProducer { private static final String XSD_PATH = getConfig("processador.xsd.path");