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

郑州营销型网站公司电话各行各业网站建设

郑州营销型网站公司电话,各行各业网站建设,创建门户网站,新乡网站建设-中国互联在实际开发中#xff0c;SpringMVC 负责扫描和加载 Controller 层的 Bean 对象#xff0c;而业务层和数据层等其他模块的 Bean 则由 Spring 框架负责扫描和加载。那么#xff0c;如何控制 Spring 仅加载除了 Controller 层之外的其他 Bean 呢#xff1f;为了解决这个问题SpringMVC 负责扫描和加载 Controller 层的 Bean 对象而业务层和数据层等其他模块的 Bean 则由 Spring 框架负责扫描和加载。那么如何控制 Spring 仅加载除了 Controller 层之外的其他 Bean 呢为了解决这个问题通常可以采取以下两种方案来避免 Spring 错误地加载 SpringMVC 的 Bean 直接指定在 Spring 的配置中精确设定扫描范围只加载特定的包例如 service 包和 dao 包。过滤排除将 Spring 的扫描范围设定为 com.it假设 groupId 为 com.it并排除 controller 包内的 Bean。 当然在实际开发中有时也会选择不区分 Spring 和 SpringMVC 的环境将它们加载到同一个环境中。这里创建一个入门版的 SpringMVC 项目进行演示创建过程可以参考 SpringMVC 快速入门。假设现在的 SpringMVC 配置类和启动配置类如下 Configuration ComponentScan(com.it.controller) public class SpringMvcConfig { }public class InitConfig extends AbstractDispatcherServletInitializer {// 用于加载 SpringMVC 容器配置Overrideprotected WebApplicationContext createServletApplicationContext() {AnnotationConfigWebApplicationContext ctx new AnnotationConfigWebApplicationContext();ctx.register(SpringMvcConfig.class);return ctx;}// 设置哪些请求归属 SpringMVC 处理Overrideprotected String[] getServletMappings() {// 设置所有的请求归属 SpringMVC 处理return new String[]{/};}// 加载 Spring 容器配置Overrideprotected WebApplicationContext createRootApplicationContext() {AnnotationConfigWebApplicationContext ctx new AnnotationConfigWebApplicationContext();ctx.register(SpringConfig.class);return ctx;} }方式 1直接指定 在 Spring 配置类中通过 ComponentScan 直接指定多个待扫描模块 Configuration ComponentScan({com.it.service, com.it.dao}) public class SpringConfig { }方式 2过滤排除 在 Spring 配置类中通过 ComponentScan 排除不扫描模块 Configuration ComponentScan(value com.it,excludeFilters ComponentScan.Filter(type FilterType.ANNOTATION,classes Controller.class) ) public class SpringConfig { }这里按照注解类型排除不需要扫描的模块说明一下ComponentScan 存在两个重要的属性 excludeFilters排除扫描路径中加载的 Bean需要指定类别type与具体项classesincludeFilters加载指定的 Bean需要指定类别type与具体项classes 测试 在 com.it 下创建一个 App 类观察运行后是否能获取到 Controller 层 Bean public class App {public static void main(String[] args) {AnnotationConfigApplicationContext ctx new AnnotationConfigApplicationContext(SpringConfig.class);System.out.println(ctx.getBean(UserController.class));} }测试前需要将 SpringMvcConfig 类上的 Configuration 注解先注释掉因为 SpringConfig 在设置扫描 com.it 包时如果包中某个类添加了 Configuration 注解那么这个类被扫描的同时该类 ComponentScan 指定的 com.it.controller 也会被扫描这样会影响 Bean 加载控制的测试效果。 优化 在实际开发中可以优化 InitConfig 类中加载 Spring 和 SpringMVC 容器配置的过程。通过继承 AbstractDispatcherServletInitializer 类的子类使得配置过程更加简洁 public class InitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {Overrideprotected Class?[] getRootConfigClasses() {return new Class[]{SpringConfig.class};}Overrideprotected Class?[] getServletConfigClasses() {return new Class[]{SpringMvcConfig.class};}Overrideprotected String[] getServletMappings() {return new String[]{/};} }
http://www.w-s-a.com/news/620171/

相关文章:

  • 淮安软件园哪家做网站各网站特点
  • 网站长尾关键词排名软件重庆荣昌网站建设
  • 建个商城网站多少钱茂名专业网站建设
  • 开通公司网站免费的网站app下载
  • 跨境电商网站模板wordpress壁纸
  • 国内做网站网站代理电子商务网站建设与维护概述
  • 如何做地方网站推广沈阳网势科技有限公司
  • 哈尔滨网站优化技术涵江网站建设
  • 做网站搞笑口号wordpress全屏动画
  • 怎么可以建网站小程序代理项目
  • 怎样做软件网站哪个网站用帝国cms做的
  • 网站开发编程的工作方法wordpress dux-plus
  • 廊坊电子商务网站建设公司网站进不去qq空间
  • 南宁网站推广费用创意网页设计素材模板
  • 深圳技术支持 骏域网站建设wordpress 酒主题
  • 东莞网站建设+旅游网站改版数据来源表改怎么做
  • 手机端做的优秀的网站设计企业做网站大概多少钱
  • 优化网站使用体验手机网站解析域名
  • 网站制作 商务做网站的软件名字全拼
  • 阿里巴巴网官方网站温州网站建设设计
  • 传奇购买域名做网站国外网站设计 网址
  • 西安凤城二路网站建设seo网站是什么
  • 网站后台如何更换在线qq咨询代码在线种子资源网
  • 东莞网站优化制作免费中文wordpress主题下载
  • 东莞建筑设计院排名网络优化论文
  • 做牙工作网站郑州前端开发培训机构
  • 温州专业建站网站制作的管理
  • 公司网站开发策划书有没有专门做教程的网站
  • 江苏省工程建设信息网站一天赚1000块钱的游戏
  • 制作响应式网站报价品牌建设整体体系包括什么