This is how they declare a resource-ref in ejb-jar.xml :
<enterprise-beans>
<session>
<ejb-name>ResourceBean</ejb-name>
<resource-ref>
<res-ref-name>jdbc/employee</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
</resource-ref>
</session>
</enterprise-beans>
at this link: http://javahowto.blogspot.ca/2006/06/5-ways-to-get-resources-in-ejb-3.html
Now if I have another session bean that needs to use the same resource-ref, do I have to declare it again inside the second EJB? Or is there a workaround?
Prior to EE 6 (available in WebSphere Application Server 8.0), there is no way to share resource-ref across EJBs. You must redeclare the resource-ref in each EJB.
In EE 6, you can declare the resource-ref with a name such as java:module/env/jdbc/employee, and it will be visible to all EJBs in the module (and java:app is visible to all modules, and java:global is visible to all apps).
Related
I deployed a global module with remote ejbs defined, but I can't access them from deployed applications.
Here is the interface:
#Remote
public interface ICryptoAPI..
and bean definition:
#Stateless
public class CryptoAPI implements ICryptoAPI ...
How can I find jndi name of the ejbs deployed, since default #Ejb cannot find bean? Just to mention, /subsystem=naming:jndi-view() from jboss-cli doesn't print anything about deployed module and there are no errors in wildfly log.
Maybe, it is not possible to define injectable ejbs in global modules?
The portable JNDI name, an EJB is bound to, depends on how beans are deployed and some configurations (e.g. deployment descriptors).
In addition to the portable JNDI name, JBoss provides access from a remote VM within the java:jboss/exported namespace.
For your convenience, JBoss' default logging shows the JNDI names, an EJB is bound to, on console and in the server logfile upon deployment. The logger is org.jboss.as.ejb3.deployment on INFO level.
Example:
12:00:00,000 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-6) WFLYEJB0473: JNDI bindings for session bean named 'MyBean' in deployment unit 'subdeployment "my-beans.jar" of deployment "my-app.ear"' are as follows:
java:global/my-app/my-beans/MyBean!my.package.MyBeanRemote
java:app/my-beans/MyBean!my.package.MyBeanRemote
java:module/MyBean!my.package.MyBeanRemote
java:jboss/exported/my-app/my-beans/MyBean!my.package.MyBeanRemote
For accesing the EJB, you can do a manual JNDI lookup or use the #EJB annotations lookup method for injection.
While deploying EAR via HUDSON to Websphere 9.0
WebSphere throws following error
ADMA0205E: A validation error occurred in task Binding enterprise Bean to JNDI names. Java Naming and Directory Interface (JNDI) names for the bean and its local/remote home are both specified for enterprise bean XXXXX in module XXXX. You can provide either JNDI name for the bean or JNDI names for its local/remote home. But you cannot provide both.
can you please let me know if am doing anything wrong.
This normally indicates that the application has a problem in the ibm-ejb-jar-bnd.xml file. Specifically, for the bean XXXXX in module XXXX, there is a binding configuration that specifies both the simple-binding-name attribute and one of the following : local-home-binding-name or remote-home-binding-name attributes, or the <interface> element. simple-binding-name is not compatible with these other attributes/element.
Information about the format of the ibm-ejb-jar-bnd.xml file is available here:
https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/cejb_bindingsejbfp.html
In one hand, I have a Stateless EJB Bean which implements a remote interface.
#Stateless(name = "ejbBean")
#Remote(TimedBean.class)
public class TimedBeanImpl implements TimedBean
...
On the other hand, I have a Servlet client where I need to inject this EJB bean for invoking its operations. The injection referts to a JNDI automatically generated by the server:
public class LoadTimer implements ServletContextListener {
// EAR Local Mapping - EAR Dev Mapping
// #EJB(mappedName = "java:global/appTest/appTestModuleOne-01.00.00/ejbBean")
#EJB(mappedName = "java:global/appTest-01.00.00/appTestModuleOne-01.00.00/ejbBean")
private TimedBean timedBean;
#Override
public void contextInitialized(ServletContextEvent servletcontextevent) {
...
It works.
But the fact of referencing the jndi automatically generated makes the solution highly dependent on the specific environment:
It depends on the server. For example, my local server for testing it's a JBOSS 7.1 and my dev server it's a JBOSS EAP 6.2, and the automatically generated jndi's are different.
It depends on the packaging. Not is the same refers to the ejbBean deploying in a EAR file than in a WAR file.
And it depends on the version of artifacts. More changes.
I want, if possible, is to specify a unique name for the bean can be referred to the servlet in each server, for each version and packaging, in order not to have to be making continuous changes in development and avoid errors in deployments.
Greetings!
You can use <application-name> in application.xml and <module-name> in your module descriptor (web.xml or ejb-jar.xml) to mitigate the hardcoded version numbers. (Note that as of EE 6, you should use #EJB(lookup="...") rather mappedName.) The spec also requires that your application server give you an option to override the lookup name of the #EJB reference while deploying the application, so it should not matter what is hardcoded in your application at development time.
I have the same EJB module with a bean inside an EAR that is server side and an EAR that is the client side.
Can I have this situation?
Because I'm getting this error http://justpaste.it/gfs3
without understand how to fix it.
You have answer in the stack trace:
The short-form default binding 'com.demo.view.RitornaPersonaRemote'
is ambiguous because multiple beans implement the interface :
[RitornaPersonaSenzaClientEAR#RitornaPersonaSenzaClient.jar#RitornaPersona,
RitornaPersonaWebSenzaClientEAR#RitornaPersonaSenzaClient.jar#RitornaPersona].
Provide an interface specific binding or use the long-form default binding on lookup.]
If you are asking whether you may have same EJB jar in multiple project - the answer is yes you can. However during deployment you have to use long-form JNDI, provide different JNDI name for beans in other module or disable short names. You cannot register two beans under same name.
Long name would be in the form RitornaPersonaSenzaClientEAR#RitornaPersonaSenzaClient.jar#com.demo.view.RitornaPersonaRemote
See detailed info here - EJB 3.0 and EJB 3.1 application bindings overview
UPDATE
To disable short names perform the following steps:
Go to Application servers > server1 > Process definition > Java Virtual Machine > Custom properties
Define new custom property com.ibm.websphere.ejbcontainer.disableShortDefaultBindings with value * to disable short bindings for all apps or AppName1|AppName2 to just disable short bindings in selected apps.
Example default bindings are shown in SystemOut.log:
The binding location is: ejblocal:JPADepEar/JPADepEJB.jar/TableTester#ejb.TableTester
The binding location is: ejblocal:ejb.TableTester
The binding location is: java:global/JPADepEar/JPADepEJB/TableTester!ejb.TableTester
And with disableShortDefaultBindings property set there is no short form:
The binding location is: ejblocal:JPADepEar/JPADepEJB.jar/TableTester#ejb.TableTester
The binding location is: java:global/JPADepEar/JPADepEJB/TableTester!ejb.TableTester
There is a bug in the documentation and the correct property is com.ibm.websphere.ejbcontainer.disableShortDefaultBindings not com.ibm.websphere.ejbcontainer.disableShortFormBinding
In my case:- i did install abc.ear and xyz.ear both ear was independent do dependency with each other.
I was calling abc.ear using client-lookup but that was giving me
com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object.
[Root exception is com.ibm.websphere.ejbcontainer.AmbiguousEJBReferenceException: The short-form default binding
'com.ejb.abc' is ambiguous because multiple beans implement the interface :
[xyz-ear#rabc-ejb-1.0.jar#abcInrerfaceImpl, rabc-ear#rabc-ejb-1.0.jar
abcInrerfaceImpl]. Provide an interface specific binding or use the long-form default binding on lookup.]
my Solution was:-
i removed the abc.jar that was inside another application(xyz.ear)
C:\Program Files\IBM\WebSphere\AppServer\profiles\AppSrv01\wstemp\92668751\workspace\cells\mypc00Node01Cell\applications\xyz-ear.ear
'
Then solution client-lookup works fine.
To avoid this in future this is better practice to create separate node on your IBM-WAS server and install both application on different node.
So both application component will not mess up.
I'm investigating the pros and cons of switching from Struts 2 to Spring MVC 3. I've gone the route of building test projects using annotation based controllers, but I'm struggling with how to set up my connection to my repository object. In XML it'd be this:
<bean name="/viewfood.htm"
class="hellospringmvc.controller.ViewFoodController"
p:foodRepository-ref="foodRepository"
p:viewName="viewfood" />
with the reference to the repository in the properties. How do I translate this into an annotation?
In the bean above you are referencing the foodRepository bean from the controller . To manage this with annotation ,
Use component scan to autodetect the #Repository , #Service annotation - It dosen't matter much if you use either of them but #Repository makes sense .
Mark your DAO class object with #Repository . See here for the reference
The beans are then autodetected and you will have a bean with the first letter of class name lower cased . or you can specify your own bean name using #Repository("foodRepository")