dependency cycle on spring WebSocket interceptor and spring cloud stream - spring-websocket

i am trying to create a websocket interceptor that do send a message using MessageChannel from spring cloud stream . i am facing a dependency cycle
┌─────┐
| myChannelInterceptor defined in file [/Users/shahbour/IdeaProjects/proxy/target/classes/com/xxxxx/proxy/broker/MyChannelInterceptor.class]
↑ ↓
| com.xxxx.proxy.service.XxxxxBinding (field private java.util.Map org.springframework.cloud.stream.binding.BindableProxyFactory.bindingTargetFactories)
↑ ↓
| org.springframework.cloud.stream.config.BindingServiceConfiguration (field private java.util.List org.springframework.cloud.stream.config.BindingServiceConfiguration.customMessageConverters)
↑ ↓
| org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration
↑ ↓
| webSocketConfig defined in file [/Users/shahbour/IdeaProjects/proxy/target/classes/com/xxxx/proxy/config/WebSocketConfig.class]
└─────┘
My problem is that i need to inject a MessageChannel into the websocket interceptor
I am receiving the below error if i use #Autowire
org.springframework.context.ApplicationContextException: Failed to start bean 'subProtocolWebSocketHandler'; nested exception is java.lang.IllegalArgumentException: No handlers
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:167) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:879) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at com.xxxx.proxy.xxxxxxProxyApplication.main(XxxxxProxyApplication.java:29) [classes/:na]
Caused by: java.lang.IllegalArgumentException: No handlers
at org.springframework.util.Assert.isTrue(Assert.java:92) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.start(SubProtocolWebSocketHandler.java:244) ~[spring-websocket-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 15 common frames omitted

OK. Thank you! No I see the problem.
Look:
Your MyChannelInterceptor depends on the auto-created channel by the BinderService.
That one tries to infer MessageConverters from the application context.
The AbstractMessageBrokerConfiguration provides one in face of CompositeMessageConverter brokerMessageConverter
That class is instantiated by the #EnableWebSocketMessageBroker
which, in turn, scans your WebSocketConfig because of the AbstractWebSocketMessageBrokerConfigurer
And this last one wants your MyChannelInterceptor to be injected.
Not sure how to fix that as an out-of-the-box feature, but here is some kind of workaround:
public class MyChannelInterceptor extends ChannelInterceptorAdapter {
#Autowired
private MessageChannel output;
#Configuration
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
#Bean
public MyChannelInterceptor myChannelInterceptor() {
return new MyChannelInterceptor();
}
...
#Override
public void configureClientInboundChannel(ChannelRegistration registration) {
registration.setInterceptors(myChannelInterceptor());
}

Related

unable to start Grail application

I am learning Grail and was trying to below code but could not start the application after referencing two classes make and model in vehicle class. also I am adding year as an integer in vehicle class
Running application...
2017-03-05 08:48:32.229 ERROR --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'grailsCacheFilter': Cannot create inner bean '(inner bean)#692e68e0' of type [grails.plugin.cache.web.filter.simple.MemoryPageFragmentCachingFilter] while setting bean property 'filter'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)#692e68e0': Unsatisfied dependency expressed through method 'setUrlMappingsHandlerMapping' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'urlMappingsHandlerMapping': Unsatisfied dependency expressed through method 'setWebRequestInterceptors' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openSessionInViewInterceptor': Cannot resolve reference to bean 'hibernateDatastore' while setting bean property 'hibernateDatastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.MappingException:
**Could not determine type for: groovy.lang.Binding, at table: vhicle, for columns: [org.hibernate.mapping.Column(binding)]**
2017-03-05 08:48:32.392 ERROR --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
at grails.boot.GrailsApp.run(GrailsApp.groovy:387)
at grails.boot.GrailsApp.run(GrailsApp.groovy:374)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
Process 'command '/usr/lib/jvm/java-7-oracle/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
| Error Failed to start server (Use --stacktrace to see the full trace)
Here is my Vhicle.groovy
package com.example
class Vehicle {
Integer year
String name
Model model
Make make
static constraints = {
year min: 1900
name maxSize: 255
}
}
def vehicle = Vehicle.findByName('pickup')
if(vehicle) {
println vehicle.model // e.g, 'Titan'
println vehicle.make // e.g, 'Nissan'
}
Model.groovy
package com.example
class Model {
String name
static belongsTo = [ make: Make ]
static constraints = {
}
String to_String(){
name
}
}
Here is my Make.groovy
package com.example
class Make {
String name
static constraints = {
}
String to_String(){
name
}
}
Check your groovy file name vehicle.groovy you have misspelled. You have written like vhicle.groovy it should be Vehicle.groovy as Class name is Vehicle.
As it says in the exception:
at table: vhicle
You've misspelled vehicle somewhere

WELD-001408: Unsatisfied dependencies for type List with qualifiers

I'm stuck with the infamous WELD-001408 that everyone programming with CDI has come across in one way or other. Using Oracle JDK 1.8.0_25, Wildfly 8.2.0.Final. My code is as follows:
module availability-service (war) depends on module hospital-user (jar). Former has a beans.xml in WEB-INF and later in META-INF, even though CDI 1.1 doesn't require a beans.xml.
In hospital-user:
#ApplicationScoped
public class Users {
#Produces
#Doctors
public List<Doctor> getDoctors() {
return getUsers("/doctors.json", Doctor.class);
}
#Produces
#Patients
public List<Patient> getPatients() {
return getUsers("/patients.json", Patient.class);
}
}
Doctors annotation (Patients is similar except for the name):
#Qualifier
#Retention(RUNTIME)
#Target({ FIELD, METHOD })
public #interface Doctors {
}
In availability-service:
#ApplicationScoped
public class AvailabilityService {
#Inject
#Doctors
private List<Doctor> doctors;
}
Error:
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type List<Doctor> with qualifiers #Doctors
at injection point [BackedAnnotatedField] #Inject #Doctors private name.abhijitsarkar.microservices.availability.AvailabilityService.doctors
at name.abhijitsarkar.microservices.availability.AvailabilityService.doctors(AvailabilityService.java:0)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:372)
If I inject the Users instead of the List, it works. Here is a sample Maven project that demonstrates the problem with 4 classes. Just run mvn clean test.
In the sample Maven project that you provided, dependency injection in the test class isn't available as you specified your Arquillian deployment as #Deployment(testable = true).
When set to true, which is the default, the test passes.
Besides, adding the following injection point in the test method:
#Inject
#Employees
List<Employee> employees;
works fine which demonstrates that your bean deployment is valid.
It continues to work when the Arquillian deployment matches exactly the application WAR structure that you've depicted, i.e.:
#Deployment
public static WebArchive createDeployment() {
return create(WebArchive.class, "availability-service.war")
.addAsLibraries(create(JavaArchive.class, "hospital-user.jar")
.addPackages(true, Filters.exclude(".*Test.*"), Producer.class.getPackage())
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"))
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}

ElmahR Dashboard throws "Unable to compile template" error when Sending Commands

I worked through the Setup documentation found here. I have a sample dashboard application and a sample client application which throws Elmah errors into a SQL database.
The client application has elmah working correctly and I can view the error logs at elmah.axd. When I attempt to access the Dashboard application the page loads and kicks off the "Sending Commands" message. I then get a 500 Internal Server error from the first "send?transport=..." command.
The Dashboard app is an ASP.Net MVC 5 app running on my localhost.
This is the URL that generates the error:
http://localhost/ElmahR/elmahr/commands/send?transport=serverSentEvents&connectionToken=k6HUNtFtmSXrJZgH_2oexTg_cx-el2G7PhJ6NZD4aBLT_svpboE31meZG4wazu7VDS8_WWRjnnV-yGSVhBzBbYWlXFTo08onRvNCzYgYhH5kwMw9KvKOSQIakT6Wzv_Y0
When I inspect that error, this is what I get:
RazorEngine.Templating.TemplateCompilationException
Unable to compile template. Source file 'C:\Windows\TEMP\lahvjqh3.0.cs' could not be found Other compilation errors may have occurred. Check the Errors property for more information.
System.AggregateException: One or more errors occurred. ---> RazorEngine.Templating.TemplateCompilationException: Unable to compile template. Source file 'C:\Windows\TEMP\lahvjqh3.0.cs' could not be found
Other compilation errors may have occurred. Check the Errors property for more information.
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Compilation\DirectCompilerServiceBase.cs:line 100
at RazorEngine.Templating.TemplateService.CreateTemplateType(String razorTemplate, Type modelType) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 256
at RazorEngine.Templating.TemplateService.CreateTemplate(String razorTemplate, Type templateType, Object model) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 127
at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 435
at ElmahR.Core.Plugins.<BuildPlugins>b__a(<>f__AnonymousType2`2 <>h__TransparentIdentifier6)
at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at ElmahR.Core.StartupConnection.<.ctor>b__1(IConnection c, IRequest r, String cid, String d)
at ElmahR.Core.StartupConnection.OnReceived(IRequest request, String connectionId, String data)
at Microsoft.AspNet.SignalR.PersistentConnection.<>c__DisplayClassa.<>c__DisplayClassc.<ProcessRequest>b__7()
at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod(Func`1 func)
--- End of inner exception stack trace ---
at Microsoft.Owin.Host.SystemWeb.CallContextAsyncResult.End(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)
---> (Inner Exception #0) RazorEngine.Templating.TemplateCompilationException: Unable to compile template. Source file 'C:\Windows\TEMP\lahvjqh3.0.cs' could not be found
Other compilation errors may have occurred. Check the Errors property for more information.
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Compilation\DirectCompilerServiceBase.cs:line 100
at RazorEngine.Templating.TemplateService.CreateTemplateType(String razorTemplate, Type modelType) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 256
at RazorEngine.Templating.TemplateService.CreateTemplate(String razorTemplate, Type templateType, Object model) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 127
at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 435
at ElmahR.Core.Plugins.<BuildPlugins>b__a(<>f__AnonymousType2`2 <>h__TransparentIdentifier6)
at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at ElmahR.Core.StartupConnection.<.ctor>b__1(IConnection c, IRequest r, String cid, String d)
at ElmahR.Core.StartupConnection.OnReceived(IRequest request, String connectionId, String data)
at Microsoft.AspNet.SignalR.PersistentConnection.<>c__DisplayClassa.<>c__DisplayClassc.<ProcessRequest>b__7()
at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod(Func`1 func)<---
Any idea what might be configured incorrectly for it to throw this error? Is is something I need to change with Razor?
This is what I see:

Transactions not starting on JSF #ViewScoped #Stateless bean

I have a JSF 2 #ViewScoped based webapp, that I cannot get the transactions to go with correctly, or rather: they don't start at all.
I'm using Java EE 6's CDI and EJB3, too.
Here's the main bean:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
...
#ManagedBean
#ViewScoped
#Stateless
public class PqManager implements Serializable
{
private List<PqListItem> pqItems;
#Inject
private PqService pqService;
public List<PqListItem> getPqItems()
{
if ( pqItems == null )
{
pqItems = pqService.findActivePqs();
}
return pqItems;
}
...
}
The view-scoped bean is used from a JSF page to display a simple list in a datatable. It was made view-scoped because it has AJAX-based operations to add items, remove items, and to sort them via RichFaces (filtering).
I added #Stateless for every method invocation to start a transaction (or create a new one if none exists, the default is TransactionAttributeType.REQUIRED). This idea was taken from the book 'Core JavaServer Faces, 3rd ed.', however I haven't found any examples that would match my own.
Injected PqService class (it doesn't make a difference to use #EJB instead):
#Stateless
public class PqService extends JpaCrudService
{
...
public List<PqListItem> findActivePqs()
{
return em.createQuery("SELECT NEW ... whatever not interesting here... WHERE pq.workflow = '" + Workflow.ACTIVE + "' GROUP BY pq.id", PqListItem.class).getResultList();
}
...
}
JpaCrudService (basically taken from Adam Bien's example http://www.adam-bien.com/roller/abien/entry/generic_crud_service_aka_dao):
//#Stateless
//#Local(CrudService.class)
#TransactionAttribute(TransactionAttributeType.MANDATORY)
public abstract class JpaCrudService implements CrudService
{
#PersistenceContext(unitName = "PqGeneratorPu")
protected EntityManager em;
#Override
public <T> T create(T t)
{
em.persist(t);
em.flush();
em.refresh(t);
return t;
}
...
}
The only difference is that I subclass JpaCrudService because I don't like queries stored in/at the entities. So I omitted the #Local annotation (correct me if that's wrong). #Stateless isn't inherited AFAIK and I only inject the subclasses so I also commented that one out.
That said, the bean is then accessed from a JSF page:
<rich:dataTable value="#{pqManager.pqItems}"
var="pq">
<f:facet name="header">
<h:outputText value="Active" />
</f:facet>
...
However, when loading the page, I get an exception:
javax.ejb.EJBTransactionRequiredException: Transaction is required for invocation: org.jboss.invocation.InterceptorContext#7a6c1c92
at org.jboss.as.ejb3.tx.CMTTxInterceptor.mandatory(CMTTxInterceptor.java:255)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:184)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)
at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72)
at de.company.webapp.service.PqService$$$view95.findActivePqsFor(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:111)
at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105)
at de.company.webapp.service.PqService$Proxy$_$$_Weld$Proxy$.findActivePqs(PqService$Proxy$_$$_Weld$Proxy$.java)
at de.company.webapp.facade.PqManager.getPqItems(PqManager.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
.
.
.
It fails because the call pqService.findActivePqsFor() doesn't run in an existing transaction (TransactionAttributeType.MANDATORY, which is inherited AFAIK).
Note, that the page is displayed correctly without using transactions by deleting the TransactionAttributeType.MANDATORY on the JpaCrudService and using an extended entity manager, but this was just for testing purposes.
But why isn't this working? Why isn't the transaction started here? Is there anything with the JSF #ViewScoped bean? Incompatible?
How do you repair this?
PS: I'm using JBoss AS 7.1.1.
Of you're using CDI drop the JSF annotations. JSF annotations don't control EJBs the way CDI will. You're probably confusing the container with the annotations being used. You could also use MyFaces CODI for some extensions or look at recreating the ViewScope with CDI. There are a few examples online.

Injecting #Stateful bean into another #Stateful bean

On a glassfish 3.1 server, I have a #Stateful session bean which is injected into another stateful session bean.
The stateful session bean which is injected presents my entity access layer, it itself has it's EntityManager injected with #PersistenceContext and it looks like this.
#Stateful
MyEAO {
#PersistenceContext
EntityManager em;
MyEAO() {
// default constructor
}
....
}
This access layer is injected into another stateful bean:
#Stateful
public class ShopAdmin implements ShopAdminInterface {
#EJB MyEAO;
....
}
This worked! - BUT NOW as soon as I added another constructor to MyEAO, injecting MyEAO into the 2nd bean fails with an exception.
The strange thing is, that both beans used to be #Stateless session beans in the past and there were no problems at all.
BTW, I used the second constructor to pass the entity manager for my JUnit tests which run outside of the glassfish container.
Short: In the "stateless era" everything worked as expected!
I'm quite new to EJB - so what am I missing here ?
Here is the stack trace:
com.sun.faces.mgbean.ManagedBeanCreationException: Bei der Ressourcen-Einspeisung auf dem verwalteten Bean securityGuardBean ist ein Fehler aufgetreten.
at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:211)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:99)
at com.sun.el.parser.AstValue.getTarget(AstValue.java:127)
at com.sun.el.parser.AstValue.invoke(AstValue.java:217)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2508)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)
at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2129)
at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2077)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:286)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:244)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:232)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:680)
Caused by: com.sun.faces.spi.InjectionProviderException: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Local ejb-ref name=de.sdata.service.SecurityGuardBean/sgi,Local 3.x interface =de.sdata.service.SecurityGuardInterface resolved to intra-app EJB SecurityGuard in module sdataEJB.jar,ejb-link=sdataEJB.jar#SecurityGuard,lookup=,mappedName=,jndi-name=,refType=Session into class de.sdata.service.SecurityGuardBean: Lookup failed for 'java:comp/env/de.sdata.service.SecurityGuardBean/sgi' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
at org.glassfish.faces.integration.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:194)
at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:205)
... 48 more
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Local ejb-ref name=de.sdata.service.SecurityGuardBean/sgi,Local 3.x interface =de.sdata.service.SecurityGuardInterface resolved to intra-app EJB SecurityGuard in module sdataEJB.jar,ejb-link=sdataEJB.jar#SecurityGuard,lookup=,mappedName=,jndi-name=,refType=Session into class de.sdata.service.SecurityGuardBean: Lookup failed for 'java:comp/env/de.sdata.service.SecurityGuardBean/sgi' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:703)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:470)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:171)
at org.glassfish.faces.integration.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:184)
... 49 more
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/de.sdata.service.SecurityGuardBean/sgi' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: No object bound for java:comp/env/de.sdata.service.SecurityGuardBean/sgi [Root exception is java.lang.reflect.UndeclaredThrowableException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:599)
... 52 more
Caused by: javax.naming.NameNotFoundException: No object bound for java:comp/env/de.sdata.service.SecurityGuardBean/sgi [Root exception is java.lang.reflect.UndeclaredThrowableException]
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:242)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
... 56 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at $Proxy273.create(Unknown Source)
at com.sun.ejb.EJBUtils.resolveEjbRefObject(EJBUtils.java:366)
at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:190)
at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1106)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:776)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:744)
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:172)
... 57 more
Caused by: javax.ejb.CreateException: ERROR creating stateful SessionBean
at com.sun.ejb.containers.StatefulSessionContainer.createEJBLocalBusinessObjectImpl(StatefulSessionContainer.java:551)
at com.sun.ejb.containers.BaseContainer.createEJBLocalBusinessObjectImpl(BaseContainer.java:2486)
at com.sun.ejb.containers.EJBLocalHomeImpl.createEJBLocalBusinessObjectImpl(EJBLocalHomeImpl.java:117)
at com.sun.ejb.containers.EJBLocalHomeInvocationHandler.invoke(EJBLocalHomeInvocationHandler.java:177)
... 64 more
Caused by: java.lang.InstantiationException: de.sdata.service._SecurityGuard_Serializable
at java.lang.Class.newInstance0(Class.java:340)
at java.lang.Class.newInstance(Class.java:308)
at com.sun.ejb.containers.StatefulSessionContainer._constructEJBInstance(StatefulSessionContainer.java:566)
at com.sun.ejb.containers.BaseContainer.createEjbInstanceAndContext(BaseContainer.java:1643)
at com.sun.ejb.containers.StatefulSessionContainer.createBeanInstance(StatefulSessionContainer.java:578)
at com.sun.ejb.containers.StatefulSessionContainer.createEJBLocalBusinessObjectImpl(StatefulSessionContainer.java:532)
... 67 more
I suspect that you don't have an explicit no-arg constructor in your class.
IMO it is not a good solution to add special constructor to the bean class because you need to
set some field for the tests. There are some nice tools that can do a lot of tricks for you.
Take a look at http://unitils.org/cookbook.html -->Test a JPA DAO which should be what you need.
Best,
A

Resources