当前位置: 首页 > 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.hkea.cn/news/14465711/

相关文章:

  • 营销型网站设计思路武隆网站建设哪家好
  • 在线课程网站开发价格萍乡做网站
  • 苏州免费网站建设自己做一元夺宝网站
  • 上往建站平台建设网站
  • 肃宁县网站建设网站建设 网站内容 采集
  • 有没有学做蛋糕的网站和视频大型网站运营步骤
  • 简约淘宝网站模板免费下载陇西网站建设 室内设计
  • 专做恐怖片的网站国外地图搜房网站建设
  • 江西高端网站定制国内开源网站
  • 如何将网站开发成微信小程序网站建设移动端官网
  • 杭州企业网站制作哪家好郑州做网站的外包公司
  • 直播课网站怎样做的云服务器gpu租用
  • 怎么修改网站首页html代码商城网站开发价格
  • 辽宁建设厅新网站互动营销是什么意思
  • 北京移动网站建设公司价格南通哪些公司做网站
  • wordpress整站安装宁波妇科专家哪个最好
  • 电脑做系统哪个网站比较好用广州市建设局网站
  • 行业网站系统东莞做网站哪家最好
  • 聊城九洲建设有限公司网站中文域名注册流程
  • 响应式网站头部视频网站用什么做
  • 河南科兴建设有限公司网站门户网站建设投标书
  • 电子商务网站规划与管理庆阳市建设局网站
  • 网站模板打包下载sem竞价是什么意思
  • 爱心互助网站开发站长平台seo
  • 阜蒙县建设学校网站是什么wordpress弄个人博客好吗
  • 购物网站建设多少钱手机网站开发相关问题
  • 网站开发用什么电脑做网站的前台用什么工具
  • iis7.5发布网站教程网站设计模板是什么
  • 展示型商城订单网站建设赤峰建设银行网站
  • 网站备案对网站负责人的要求新建网站如何推广