Java EE vs Spring. Or: What is a standard? html
J2EE是一系列技术标准所组成的平台。 JavaEE包含了对一系列标准(接口)的实现。 若是你要用这些接口,恐怕要使用JavaEE服务器而不单单是一个Servlet容器java
由于汤姆猫实现了servlet-api因此它知道怎么去找web.xml文件。spring
对于tomcat来讲,他没有实现JPA规范,因此当你真的要在你的web应用里头实现数据库访问sql
看一下人家sqlite实现的接口数据库
package org.sqlite; public class JDBC implements java.sql.Driver { public static final java.lang.String PREFIX = "jdbc:sqlite:"; public JDBC() { /* compiled code */ } public int getMajorVersion() { /* compiled code */ } public int getMinorVersion() { /* compiled code */ } public boolean jdbcCompliant() { /* compiled code */ } public boolean acceptsURL(java.lang.String url) { /* compiled code */ } public static boolean isValidURL(java.lang.String url) { /* compiled code */ } public java.sql.DriverPropertyInfo[] getPropertyInfo(java.lang.String url, java.util.Properties info) throws java.sql.SQLException { /* compiled code */ } public java.sql.Connection connect(java.lang.String url, java.util.Properties info) throws java.sql.SQLException { /* compiled code */ } static java.lang.String extractAddress(java.lang.String url) { /* compiled code */ } public static java.sql.Connection createConnection(java.lang.String url, java.util.Properties prop) throws java.sql.SQLException { /* compiled code */ } }
JDBC访问数据库的主要工做包括:apache
而工业界相似于JPA规范的,有Hibernateapi
那么问题来了,Spring依赖了什么javaee规范呢?tomcat
Spring只依赖于servlet-api。服务器
可是,Spring的可扩展性强得使人发指,对于实现JPA规范,他有Spring Data JPA, 它依赖于openjpa-persistence-jdbc,而openjpa实现了JSR-317 Java Persistence 2.0规范,因此的话它仍旧是能够在Tomcat里头用。注意JPA规范用的是persitence.xml的配置文件,这个好理解,跟web.xml是一个道理的。
回过头来,若是你不想用JPA,大能够用Spring自带的JDBCTemplate,它是处在org.springframework.jdbc.core里头的。
Spring的核心仍然在于CDI,正是由于这个缘由,哪怕它不去实现大部分的JavaEE规范,它也能够去兼容这些规范的实现,而后利用CDI,注入这些实现。
认识还不够全面,但愿之后还能再改改这篇文章。