cdi

Java EE 6: controlling startup of managed beans with dependencies: CDI, EJB

守給你的承諾、 提交于 2020-01-11 09:29:11
问题 I just read the very nice explanation of the various managed beans and their relations on Java EE 6 @javax.annotation.ManagedBean vs. @javax.inject.Named vs. @javax.faces.ManagedBean and as i face a annoying problem in my application i want to know if it is possible to control or influence the way how and when beans are started. In my Java EE application I use EJB, CDI and JSF2 as view technology. Via SPI a service from a third party is booted and it configures a job executor which starts

What's the overhead of creating a SLF4J loggers in static vs. non-static contexts?

China☆狼群 提交于 2020-01-10 08:45:20
问题 I've always used the following pattern to construct (SLF4J) loggers: private static final Logger log = LoggerFactory.getLogger(MyClass.class); This has worked so far, but I was wondering about the static context at some point and the need to pass in the concrete class literal all the time instead of just using a non-static logger like private final Logger log = LoggerFactory.getLogger(getClass()); This has basically been asked (and answered) before here for LOG4J Should logger be private

What is the easiest way to have CDI and JPA in Java SE?

感情迁移 提交于 2020-01-09 09:38:07
问题 I would like to have in Java SE @Stateless public class CarDAO { @Inject private EntityManager em; public Car findById(Long id) { return em.find(Car.class, id); } } @Singleton public class Application { @Inject private CarDAO carDAO; public void run() { Car car = carDAO.findById(44); System.out.println(car); } } public class EntryPoint { public static void main(String[] args) { Application application = // missing code application.run(); } } What I have to do to achieve that? I'm using

Getting a reference to EntityManager in Java EE applications using CDI

人盡茶涼 提交于 2020-01-09 08:43:31
问题 I'm using Java EE 7. I would like to know what is the proper way to inject a JPA EntityManager into an application scoped CDI bean. You can't just inject it using @PersistanceContext annotation, because EntityManager instances are not thread safe. Let's assume that we want our EntityManager to be created at the beginnig of every HTTP request processing and closed after the HTTP request is processed. Two options come into my mind: 1. Create a request scoped CDI bean which has a reference to an

when injecting EntityManager using CDI 2.0 throws java.lang.NullPointerException

你。 提交于 2020-01-07 08:25:12
问题 @ApplicationScoped public class PersonDao { @PersistenceContext private EntityManager entityManager; public List<Person> getAllPersons() { Query query=entityManager.createQuery("SELECT p FROM PersonEntity p"); List<Person> persons=query.getResultList(); return persons; } } Can you please help.. Thanks 来源: https://stackoverflow.com/questions/59541849/when-injecting-entitymanager-using-cdi-2-0-throws-java-lang-nullpointerexception

Can't get SessionContext on EJB

邮差的信 提交于 2020-01-07 04:22:24
问题 I can't get a SessionContext object on an EJB. I've tried all the options suggested on 4 Ways to Get EJBContext in EJB 3 and none of them worked. For example, the following code in my project... @Stateful public class SecurityService { @Resource private SessionContext context; @PostConstruct public void init() { } } ... generates the following exception during deploy: [#|2012-02-28T14:35:02.805-0300|SEVERE|glassfish3.1.1|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=18;

@Inject is injecting a new instance every time i use it

谁都会走 提交于 2020-01-07 02:25:06
问题 I have the following issue. (jboss 7.1 as, jsf 2 and myFaces extension filter) Two managed beans. (I have cleaned up the code). I want to retrieve LoginBean from NextBean. The problem is that every time i inject the bean i get a new instance of LoginBean and not the current one. I have tried things like @Named("name"). The bean itself (both) are invoked from the jsf pages and all data is set, but a new instance is injected every time and i cant figure out what i'm doing wrong!!! @Named

Application context path at JAX-RS 2.0 resource instance construction

北战南征 提交于 2020-01-06 14:45:15
问题 Is it possible to get the context path for a Java EE 7 application at JAX-RS 2.0 resource class instance construction time (and possibly at static class initialization time, too), or is it only available during requests to endpoints in the resource class? By context path I mean the String that would be returned by a call to a HttpServletRequest#getContextPath() within the Java EE 7 application. I imagine that you probably could have multiple context path aliases for a deployed application. If

Application context path at JAX-RS 2.0 resource instance construction

删除回忆录丶 提交于 2020-01-06 14:45:14
问题 Is it possible to get the context path for a Java EE 7 application at JAX-RS 2.0 resource class instance construction time (and possibly at static class initialization time, too), or is it only available during requests to endpoints in the resource class? By context path I mean the String that would be returned by a call to a HttpServletRequest#getContextPath() within the Java EE 7 application. I imagine that you probably could have multiple context path aliases for a deployed application. If

HK2 Jersey EJB 3 injection

廉价感情. 提交于 2020-01-06 11:48:09
问题 I followed the 22.1. Implementing Custom Injection Provider paragraph https://jersey.java.net/documentation/latest/user-guide.html#deployment I was able to develop my own injectable custom annotation following the steps described in this post: Jersey 2.x Custom Injection annotation NULL So i use these deployment instructions to bind my injectionresolver: <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>