jboss-weld

What is the difference between @Inject and @PersistenceContext?

南笙酒味 提交于 2019-12-08 16:22:40
问题 In a project using JPA, I commonly use @Inject EntityManager em; in order to obtain such an object. I saw that many code snippets in the web instead use: @PersistenceContext EntityManager em; What is the difference between these options? My code runs on JBoss EAP 6.1 and Hibernate. 回答1: @PersistenceContext is a specific annotation that declares a dependency on a container-managed entity manager. It allows you to specify more parameters like the persistence type. Setting the persistence type

Weld and Java SE

心已入冬 提交于 2019-12-07 22:01:16
问题 I'm new to Weld and have been trying to get my head around it's concepts. I have a little experience with Spring and nothing with Guice, so I'm pretty much a novice with the DI frameworks. Here's a tutorial that introduce CDI, but in the context of web apps. I'm interested to see how this works in Java SE alone. I have created the following classes, but have no idea how to test the ItemProcessor's execute method with the DefaultItemDao class (or any other alternative) in a Java SE app. Here

Debugging's step into won't work on own code: MyClass$Proxy$_$$_WeldClientProxy.myMethod() line: not available

若如初见. 提交于 2019-12-07 06:32:11
问题 When debugging I set a breakpoint to a line that calls a method from another (own) class. On step into I get a Source not found in the editor with the title MyClass$Proxy$_$$_WeldClientProxy.myMethod() line: not available in the stacktrace. I can step over those as long as I am back in the class with the breakpoint. I have the same problem using Eclipse Kepler SR 1, Eclipse Juno SR 2 and JBoss AS 7.1.1 and 7.2. 回答1: That's a common problem with autogenerated code. You believe that an object

CDI - what is the correct bean.xml format?

会有一股神秘感。 提交于 2019-12-06 20:10:50
问题 I have a question about the correct format and usage of the bean.xml file. In my projects I typically used this content for my bean.xml files (no explizit bean declaration used): <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> </beans> This works well in WildFly 8 and 9. But I have deployment

CDI lifecycle of bean, @Inject and params

别说谁变了你拦得住时间么 提交于 2019-12-06 15:13:39
问题 The view and bean were working until I tried to fix non-standard names, and I've now broken the connection between the two. Oddly, the "back" button has the correct link, but content just doesn't show, nor log. Why doesn't Detail.getComments() execute? I've been going through the weld docs and trying to better understand @Inject. There seems to be a lifecycle problem which I don't understand, either. If it's not lifecycle, then I cannot even speculate as to why Detail.getComments() never

How to test EJB method call with Arquillian Weld EE Embedded

爷,独闯天下 提交于 2019-12-06 08:49:19
问题 I would like to test an EJB, and I want to test it with Weld EE Embedded as I don't want to deploy an applicatoin server for that. Here is my class : @RunWith(Arquillian.class) public class EJBTest { @Deployment public static JavaArchive createTestArchive() { return ShrinkWrap .create(JavaArchive.class, "test.jar") .addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); } @Stateless public static class SomeService { public String someMethod() { return "test"; } }

Weld (CDI): where do I put my test-only beans.xml that configures <alternatives>?

梦想的初衷 提交于 2019-12-06 08:30:18
问题 My webapp has a non-empty production beans.xml under src/main/resources/META-INF . Now, for my tests, I need to swap out 1 bean with an alternative. Where do I put this test beans.xml which contains just this and nothing more? <?xml version="1.0" encoding="UTF-8"?> <beans ...> <alternatives> <class>...MyTestReplacement</class> </alternatives> </beans> I tried under src/test/resources/META-INF but that is ignored. I am using arquillian and my test classpath is added to the ShrinkWrap. 回答1:

Weld and Java SE

别说谁变了你拦得住时间么 提交于 2019-12-06 06:07:49
I'm new to Weld and have been trying to get my head around it's concepts. I have a little experience with Spring and nothing with Guice, so I'm pretty much a novice with the DI frameworks. Here's a tutorial that introduce CDI, but in the context of web apps. I'm interested to see how this works in Java SE alone. I have created the following classes, but have no idea how to test the ItemProcessor's execute method with the DefaultItemDao class (or any other alternative) in a Java SE app. Here're the classes: public class Item { private int value; private int limit; public Item(int v, int l) {

CDI - Observing Container Events

本小妞迷上赌 提交于 2019-12-06 00:18:25
问题 I am trying to observe both the startup and shutdown events for a CDI web application. I have an ApplicationScoped bean that listens for those events: @ApplicationScoped public class PrettyfacesStartupObserver { private static final Log LOGGER = LogFactory.getLog(PrettyfacesStartupObserver.class); public PrettyfacesStartupObserver() { LOGGER.debug("\n\n\n\n\n\n\n\n\n\nconstructor"); } public void onStartup(@Observes AfterBeanDiscovery afterBeanDiscovery ) { LOGGER.debug("\n\n\n\n\n\n\n\n\n

Debugging's step into won't work on own code: MyClass$Proxy$_$$_WeldClientProxy.myMethod() line: not available

雨燕双飞 提交于 2019-12-05 11:29:31
When debugging I set a breakpoint to a line that calls a method from another (own) class. On step into I get a Source not found in the editor with the title MyClass$Proxy$_$$_WeldClientProxy.myMethod() line: not available in the stacktrace. I can step over those as long as I am back in the class with the breakpoint. I have the same problem using Eclipse Kepler SR 1, Eclipse Juno SR 2 and JBoss AS 7.1.1 and 7.2. ewernli That's a common problem with autogenerated code. You believe that an object of yours (let's call it A) invokes a method on another object of yours (let's call it B), but the