WebLogic小记
WebLogic是美国bea公司出品的一个application server确切的说是一个基于Javaee架构的中间件,BEA WebLogic是用于开发、集成、部署和管理大型分布式Web应用、网络应用和数据库应用的Java应用服务器。将Java的动态功能和Java Enterprise标准的安全性引入大型网络应用的开发、集成、部署和管理之中。
webserver是用来构建网站的必要软件用来解析发布网页等功能,它是用纯java开发的。weblogic本来不是由bea发明的,是它从别人手中买过来,然后再加工扩展。目前weblogic在世界application server市场上占有最大的份额,其他还有象金蝶Apusic应用服务器、IBM的websphere,免费的tomcat、resin等中间件。 BEA WebLogic Server拥有处理关键Web应用系统问题所需的性能 、可扩展性和高可用性。 与BEA WebLogic Commerce ServerTM配合使用, BEA WebLogic Server可为部署适应性个性化电子商务应用系统提供完善的解决方案。
集群(Clustr) 1.WebLogic集群技术指通过一组服务器共同工作, 在多台机器间复制应用表示层和应用逻辑层的能力, 实现关键业务系统的负载分布,消除个别故障点; 2. 集群用来实现负载均衡和容错。
J2EE的4层结构 1.客户层(浏览器) Client Tier ---> Client Machine 2.Web层(HTML、Servlet、JSP) Web Tier Tier-- |-->J2EE Server Machine 3.业务层(EJB) Business Tier-- 4.EIS(关系数据库) EIS Tier ---->Database Server Machine
1.Servlet:处理HTTP请求,产生响应。 2.JSP:Java Server Pages,同Servlet。 其中包含了HTML和JSP标签、Java代码和其他信息。 3.EJB:EJB服务端组件模型简化了具有交互性、扩展性 和移植性中间组件的开发。EJB一般用于实现系统的业务逻辑。
spring为ApplicationContext提供的3种实现分别为:ClassPathXmlApplicationContext, spring为ApplicationContext提供的3种实现分别为:ClassPathXmlApplicationContext, FileSystemXmlApplicationContext和XmlWebApplicationContext,其中 XmlWebApplicationContext是专为Web工程定制的。使用举例如下:
- FileSystemXmlApplicationContext
Java代码 复制代码
- eg1.
- pplicationContext ctx = new FileSystemXmlApplicationContext("bean.xml"); // 加载单个配置文件
eg1. ApplicationContext ctx = new FileSystemXmlApplicationContext("bean.xml"); //加载单个配置文件
Java代码 复制代码
- eg2.
- String locations = {"bean1.xml", "bean2.xml", "bean3.xml"};
- ApplicationContext ctx = new FileSystemXmlApplicationContext(locations ); //加载多个配置文件
eg2. String locations = {"bean1.xml", "bean2.xml", "bean3.xml"}; ApplicationContext ctx = new FileSystemXmlApplicationContext(locations ); //加载多个配置文件
- eg3.
- ApplicationContext ctx =new FileSystemXmlApplicationContext("D:roject/bean.xml");//根据具体路径加载文件
eg3. ApplicationContext ctx =new FileSystemXmlApplicationContext("D:roject/bean.xml");//根据具体路径加载文件
-
ClassPathXmlApplicationContext
-
eg1.
-
pplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");
eg1. ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");
- eg2.
- String locations = {"bean1.xml", "bean2.xml", "bean3.xml"};
- ApplicationContext ctx = new ClassPathXmlApplication(locations);
- 注:其中FileSystemXmlApplicationContext和 ClassPathXmlApplicationContext与BeanFactory的xml文件定位方式一样是基于路径的。
eg2. String locations = {"bean1.xml", "bean2.xml", "bean3.xml"}; ApplicationContext ctx = new ClassPathXmlApplication(locations); 注:其中FileSystemXmlApplicationContext和ClassPathXmlApplicationContext与BeanFactory的xml文件定位方式一样是基于路径的。
-
XmlWebApplicationContext
- eg1.
- ServletContext servletContext = request.getSession().getServletContext();
- ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
Spring工具类:WebApplicationContextUtils 当 Web 应用集成 Spring 容器后,代表 Spring 容器的WebApplicationContext对象将以
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE 为键存放在ServletContext的属性列表中。您当然可以直接通过以下语句获取 WebApplicationContext:
WebApplicationContext wac = (WebApplicationContext)servletContext.
getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
但通过位于 org.springframework.web.context.support 包中的WebApplicationContextUtils 工具类获取 WebApplicationContext 更方便:
WebApplicationContext wac =WebApplicationContextUtils.
getWebApplicationContext(servletContext);
当 ServletContext 属性列表中不存在 WebApplicationContext 时,getWebApplicationContext() 方法不会抛出异常,它简单地返回 null。如果后续代码直接访问返回的结果将引发一个 NullPointerException 异常,而 WebApplicationContextUtils 另一个 getRequiredWebApplicationContext(ServletContext sc) 方法要求 ServletContext 属性列表中一定要包含一个有效的 WebApplicationContext 对象,否则马上抛出一个 IllegalStateException 异常。我们推荐使用后者,因为它能提前发现错误的时间,强制开发者搭建好必备的基础设施。
实例:
public class demoServlet extends HttpServlet { IDemoWS demoWS;
public void init() throws ServletException {
super.init();
ServletContext servletContext = this.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
demoWS = (ISignpicWS)ctx.getBean("demoWS");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { .....//request.getSession().getServletContext() } }
使用spring的WebApplicationContextUtils通过Request获得容器中的对象
使用spring的工具类获得容器中的bean对象
public static IMail getMail(HttpServletRequest request)throws Exception{ ServletContext sc = request.getSession().getServletContext(); ApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc); IMail mail = (IMail) ac.getBean("emailImpl"); return mail; }
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jklot66/archive/2009/11/18/4829026.aspx