当前位置: 首页 > news >正文

美术馆网站建设要求上海网站建设 方案

美术馆网站建设要求,上海网站建设 方案,如何网站网站做代理,宜昌建站Spring和Spring MVC使用父子容器的设计模式#xff0c;主要是为了实现更好的模块化和隔离#xff0c;提高系统的灵活性和可维护性。具体来说#xff0c;Spring应用通常包含两个层次的容器#xff1a;根容器#xff08;Root WebApplicationContext#xff09;和子容器主要是为了实现更好的模块化和隔离提高系统的灵活性和可维护性。具体来说Spring应用通常包含两个层次的容器根容器Root WebApplicationContext和子容器Child WebApplicationContext。下面是详细解释 1. 根容器Root WebApplicationContext 作用根容器是整个Web应用的基础容器通常用于管理应用的通用Bean如数据源DataSource、事务管理器Transaction Manager、业务服务Service Layer等。配置根容器的配置通常在 web.xml 文件中通过 ContextLoaderListener 加载配置文件通常是 applicationContext.xml。生命周期根容器在整个Web应用的生命周期内一直存在直到应用停止。 2. 子容器Child WebApplicationContext 作用子容器是每个Servlet如 DispatcherServlet的专用容器用于管理与特定Servlet相关的Bean如Controller、视图解析器ViewResolver、拦截器Interceptor等。配置子容器的配置通常在 DispatcherServlet 的配置文件中加载配置文件通常是 servlet-context.xml 或者通过 Configuration 类配置。生命周期子容器的生命周期与对应的Servlet相同当Servlet初始化时创建当Servlet销毁时销毁。 3. 父子容器的关系 继承关系子容器继承了根容器的所有Bean定义但可以覆盖或添加新的Bean定义。隔离性子容器中的Bean不会影响根容器中的Bean从而实现了模块化和隔离。资源共享子容器可以访问根容器中的Bean但根容器不能访问子容器中的Bean。 4. 具体好处 模块化根容器管理通用的、全局的Bean子容器管理特定于Servlet的Bean这种分层设计使得应用结构更加清晰易于维护和扩展。隔离性子容器中的Bean不会影响根容器中的Bean避免了不同模块之间的相互干扰提高了系统的稳定性。资源共享通过继承关系子容器可以共享根容器中的Bean减少了重复配置提高了资源利用率。灵活性可以轻松地添加新的Servlet和对应的子容器而不会影响现有的应用结构。 5. 配置示例 web.xml 配置 web-app xmlnshttp://xmlns.jcp.org/xml/ns/javaee xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsdversion3.1!-- 根容器 --context-paramparam-namecontextConfigLocation/param-nameparam-value/WEB-INF/spring/root-context.xml/param-value/context-paramlistenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listener!-- 子容器 --servletservlet-namedispatcher/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-classinit-paramparam-namecontextConfigLocation/param-nameparam-value/WEB-INF/spring/appServlet/servlet-context.xml/param-value/init-paramload-on-startup1/load-on-startup/servletservlet-mappingservlet-namedispatcher/servlet-nameurl-pattern//url-pattern/servlet-mapping /web-app 根容器配置文件root-context.xml beans xmlnshttp://www.springframework.org/schema/beansxmlns:contexthttp://www.springframework.org/schema/contextxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd!-- 数据源 --bean iddataSource classorg.springframework.jdbc.datasource.DriverManagerDataSourceproperty namedriverClassName valuecom.mysql.cj.jdbc.Driver/property nameurl valuejdbc:mysql://localhost:3306/mydb/property nameusername valueroot/property namepassword valuepassword//bean!-- 事务管理器 --bean idtransactionManager classorg.springframework.jdbc.datasource.DataSourceTransactionManagerproperty namedataSource refdataSource//bean!-- 扫描业务服务层组件 --context:component-scan base-packagecom.example.service/ /beans 子容器配置文件servlet-context.xml beans xmlnshttp://www.springframework.org/schema/beansxmlns:contexthttp://www.springframework.org/schema/contextxmlns:mvchttp://www.springframework.org/schema/mvcxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd!-- 启用Spring MVC注解驱动 --mvc:annotation-driven/!-- 扫描Controller组件 --context:component-scan base-packagecom.example.controller/!-- 配置视图解析器 --bean classorg.springframework.web.servlet.view.InternalResourceViewResolverproperty nameprefix value/WEB-INF/views//property namesuffix value.jsp//bean /beans .总结 根容器管理通用的、全局的Bean如数据源、事务管理器等。子容器管理特定于Servlet的Bean如Controller、视图解析器等。父子容器的关系子容器继承根容器的Bean定义但可以覆盖或添加新的Bean定义实现了模块化和隔离。
http://www.dnsts.com.cn/news/193418.html

相关文章:

  • 企业网站需要多大空间官方网站开发公司排名
  • 温州市企业网站制作徐州建设工程造价信息网
  • 校园信息网站开发与设计开发网站需要什么技术2022
  • 学校多语言网站建设公选课网页制作与网站建设
  • 如何添加网站后台网站建设一般需要多少费用
  • 自己做的娱乐平台网站设计一个小程序需要多少钱
  • 只用django做网站杭州马家厨房食品有限公司成立
  • 深圳网站制作哪家好薇c 做网站时字体颜色的代码
  • 如何快速建设自适应网站做网站需要学php哪些技术
  • 香河做网站shijuewangwordpress 制作模板
  • seo策划方案西安seo顾问培训
  • 做网站报价出名的石家庄优化哪家好
  • 做网站公司在哪网站 蜘蛛
  • 北京论坛建站模板python做网站毕业设计
  • 知名网站建设代理wordpress炫酷模板下载
  • 虚拟主机 多个网站wordpress 升级 ftp
  • 贵阳网站建设-中国互联网站flash模板
  • 4399小游戏网站入口移动网站好处
  • 常州做网站公司有哪些百度网页制作html
  • dedecms搭建网站做网站是否过时了
  • 黑色网站模板flask和wordpress
  • 网站建设费用还是网络专业wordpress怎么接入借口
  • vs2013做简单的网站企业网站建设的主要目的是
  • 巫溪网站建设404网站怎么做
  • 开阿里巴巴网站建设流程网页游戏传奇单职业
  • 网站超市源码cms网站内容管理系统
  • 宣城做网站网站开发公司管理模式
  • 网站制作公司网站建设公司如何建设公司网站
  • 户外运动网站建设策划秦皇岛海三建设董事长
  • 黄山市建设工程造价管理站网站网站建设案例分享