问题
I have some experience in core Java and Java EE. I read the various question on SO to understand what exactly Java EE is? And few answers in SO are: what-exactly-is-java-ee , what-is-java-ee
I have some doubts:
1) If Java EE is just a specification, who does implement them? Do Application Servers (like JBOSS, GlassFish) implement these specifications?
2) If I am correct the EJB specification is implemented by EJB container, and I believe EJB Container is part of Application Server. Now, when we as developers write an EJB code, what are we actually doing? The doubt I have is, EJB container implements the EJB specification, so are we overriding some "specification part" of the EJB? How come, some part of EJB is implemented by the EJB container and some thing which developers are writing? OR is it that some part of the EJB have to be provided by EJB container and some part to be developed by developers? I am having difficulty in undestanding this.
Please can anyone help in understanding this?
回答1:
Anybody can implement the java ee specification (JSR342), or any jsr that's part of it. When they do, they can (after buying and passing Compatibility Test Suite) claim to be compatible with the specification. There is a number of vendors with their application servers which are compatible with java ee, but no vendor implement full java ee specification. For instance, glassfish (the java ee reference implementation) uses Red Hat's CDI implementation. Sometimes, the vendor does not implement any part of the java ee specification, they grab glassfish, add their vendor specific libraries, and release it under their name. To claim compatibility, they still need to go through the certification process and run CTS.
To find out all the vendors who implement the specification is not so easy, since not all of them go through the certification process. For instance, Apache CXF is not certified on its own, rather it gets certified as part of Red Hat's JBoss.
Each specification has an API and a written pdf, both of which define the mandatory behaviour of each implementation. That is what you use when write EJB code. For instance, when you create an ejb:
import javax.ejb.Singleton;
@Singleton
public class MySingleton{
...
}
@Singleton annotation is part of the specification, but MySingleton
class is your EJB code, it's not part of the specification. The EJB container then knows what to do with the class.
回答2:
In Java specifications' cases (Java EE, JSF, other JSRs) you usually have a reference implementation created while drafting the spec (Glassfish in case of Java EE), then you have other providers who may create their own implementation of the spec (often claiming it's "better" in some way).
You as a developer then write code that can use the facilities provided by the spec, which would run correctly on any compliant implementation.
回答3:
Yes, EJB container (application server) vendors like RedHat implement the J2EE specification in their products (like JBoss).
What they don't do is implement any business logic (just the "plumbing" if you will). That is where application developers come in.
Just like Apache HTTPD or nginx implement the HTTP protocol specification, but that does not a website make.
回答4:
Anybody can implement the J2EE specification, although I wouldn't recommend you try to do it yourself. You're right, this is generally implemented by application servers so that you can run your application on a J2EE compliant container. There are also open source libraries, which when combined and added to Tomcat will implement the specification (see tomee for example).
When you write your application you are utilising the benefits of the J2EE environment which will allow you to write complex applications and focus on the needs of your specific requirements.
回答5:
1) Application Servers implements the specification and while releasing their servers they will be providing the details of their implementation. For a reference please look into this link, which specifies the various JSR implemented by JBOSS 7.
2) When we are just using any implementation provided by application server, then the instance will be taken from the implementation provided by server. Whereas if we have overrided a class then our overridden class will be provided on our operations.
来源:https://stackoverflow.com/questions/37983860/java-ee-who-implement-the-specification