Get Observer pattern on EJBs working on my web app - java

I am trying to get the EJB Observer pattern to work and it seems very straight forward from examples like this:
http://www.devchronicles.com/2011/11/javaee-revisits-design-patterns_28.html
however when I implement the method:
public void doLogging(#Observes String message){
System.out.println("Observed:"+message);
}
the #Observer annotation import does not get inserted.
Also if I do it manually as:
import javax.enterprise.event.Observes;
it does not work looking like I do not have the classes/jars.
I am using EJB 3.0 and am hoping this is not present only in 3.1.
If this is the case how can i get the Observer pattern in EJB 3.0?

It's not part of EJB, but of CDI (JSR-299).
CDI is new since Java EE 6, which also covers EJB 3.1. As you've only EJB 3.0 at hands, this means that you're still on Java EE 5. These days we're already at Java EE 7. It's about time to upgrade.
Examples of Java EE 7 servers are JBoss WildFly 8.x, Oracle GlassFish 4.x, Apache TomEE 2.x and IBM WebSphere 9.x. Examples of Java EE 6 servers are JBoss AS 6.x/7.x, Oracle GlassFish 3.x, Apache TomEE 1.x and IBM WebSphere 8.x.
See also:
What is Weld, JSR-299?

Related

Does Tomcat or Jetty support "java:comp/DefaultDataSource"

Java EE 7 requires support for a default DataSource as discussed:
Defaults in Java EE 7 (Tech Tip #37) by Arun Gupta
Using default DataSource to simplify the development and deployment of a Java EE application by Matti Tahvonen
While I realize Apache Tomcat & Eclipse Jetty provide only a small subset of Java EE features, I wonder if either provides a way to configure such a default DataSource.
Eclipse Jetty and Apache Tomcat are defined as "web containers".
They only support the Servlet spec and a few incidental/related specs around the Servlet spec (such as JSP, JAAS, JSR 356 javax.websockets, etc).
For Eclipse Jetty, there's no full Java EE support option.
For Apache Tomcat, there's TomEE to bring in more of the features of Java EE to comply with the Web Profile of Java EE.
As for comp/DefaultDataSource, neither project has a mention of it in their codebases (not even testcases or documentation).
https://github.com/eclipse/jetty.project/search?utf8=%E2%9C%93&q=DefaultDataSource&type=
https://github.com/apache/tomcat85/search?utf8=%E2%9C%93&q=DefaultDataSource&type=

The server does not support version 3.1 of the J2EE Web module specification on Eclipse

Anybody facing the same problem? When I try to change the Dynamic Web Module version, eclipse does not allows me to.
Check this Link:
Quoting the same:
The error message is quite understandable - you are attempting to execute an application that requires the server to support Servlet Spec 3.0 when it doesn't. You must therefore, run the application on a server that complies with that version of the Servlet Specification.
As far as I know you have the following options at your disposal, at the time of writing this:
Apache Tomcat 7.0
Glassfish 3.1
IBM WebSphere 8
JBoss 6 and 7

What is the equivalent implementation of service POJOs (jBoss services in jboss 6 AS) of EJB 3.0 in EJB - 3.2

Service POJOs are available which is used to define as jBoss services (in Jboss AS 6) in EJB 3.0 and the tutorial is http://docs.jboss.org/ejb3/app-server/tutorial/service/service.html and below are the related annotations.
import org.jboss.ejb3.annotation.Depends;
import org.jboss.ejb3.annotation.Management;
import org.jboss.ejb3.annotation.Service;
Similarly, could anyone please tell me the equivalent implementation in EJB 3.2 as I could not find any related jars or tutorials in wildfly 8 application server.
The functionality of org.jboss.ejb3.annotation.Depends and org.jboss.ejb3.annotation.Service can be replaced by:
javax.ejb.DependsOn
javax.ejb.Singleton
javax.ejb.Startup
There is no replacement for org.jboss.ejb3.annotation.Management

make a bean run on application start. EJB3/websphere6.1/Java1.5

I am a little new to J2EE. I have a EJB3 project and I want to run a class on application start-up, how can I do that?
I know in EJB3.1 I can use #startup and #singleton unfortunately that is not a option and I have to use EJb3 and java 5. I have done some research and there were a few solutions but I have been unable to make it work.
WebSphere Application Server version 6.1 does not support EJB3 with a standard installation. You also need to have a feature pack for EJB 3.0 installed.
See this information on the IBM site.
If this is not your issue you should update your question with more detail of what goes wrong.
Your only options prior to WebSphere 8 (with EJB 3.1 support) are:
WebSphere startup beans. These are a programming model extension
Package a WAR with the application, and use a ServletContextListener to initialize state used by the EJBs.

CDI/Weld with JEE5 and Tomcat6

I'm working on a web application that is Java EE 5. I may be able to upgrade it to EE 6 at some point, but can't at the moment. The web app is running in Tomcat 6. Can I use CDI with it?
I noticed in the Weld documentation that there is a note that I can't use session beans:
There is a major limitation to using a servlet container. Weld doesn't support deploying session beans, injection using #EJB or #PersistenceContext, or using transactional events in servlet containers. For enterprise features such as these, you should really be looking at a Java EE application server.
Does this mean I can't use the #SessionScoped annotation? If so, that would be a show-stopper for using CDI at the moment.
Any thoughts? Thanks.
This is about EJB session beans. You can use CDI with JSF in tomcat 6. Just follow the installation instructions for Weld.

Categories

Resources