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

合肥市做网站的公司有哪些seo推广软件费用

合肥市做网站的公司有哪些,seo推广软件费用,东莞常平网络推广外包,怎么才算完成一个网站在实际开发中,SpringMVC 负责扫描和加载 Controller 层的 Bean 对象,而业务层和数据层等其他模块的 Bean 则由 Spring 框架负责扫描和加载。那么,如何控制 Spring 仅加载除了 Controller 层之外的其他 Bean 呢?为了解决这个问题&a…

在实际开发中,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)与具体项(classes)
  • includeFilters:加载指定的 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/261173/

相关文章:

  • 专业网站建设费用报价今日最新消息
  • 电商网站建设论文2022黄页全国各行业
  • 能源企业 网站建设网络营销的应用
  • 如何看网站是用什么语言做的关键词排名是由什么决定的
  • 政府网站建设招标书百度网站收录
  • 已经有了网站怎么做推广哈尔滨关键词优化报价
  • 网站建设与管理作业镇江推广公司
  • 域名申请好后 如何建设网站网站权重划分
  • 佛山百度网站快速优化网络营销推广工具
  • 建一个网站需要哪些人广州seo网站推广公司
  • 建设银行etc官方网站搜索引擎优化的七个步骤
  • 做网站需要花钱吗海南百度推广运营中心
  • 做的网站显示图片很慢百度运营公司
  • 青州哪里做网站公司推广渠道
  • 网站面包屑导航怎么做的网推接单平台有哪些
  • 宜昌网站建设兼职百度关键词排名软件
  • 如何让百度快照找到自己的网站营销策划方案ppt模板
  • php网站超市广告软文是什么意思
  • b2c跨境电商宣城网站seo
  • 网站建设一流公司免费网站开发平台
  • 网站开发模式名词外贸谷歌优化
  • 网站素材 下载产品推广渠道
  • 网站后台维护怎么做seo专员工资一般多少
  • 中国网站推广黄页名录微商推广哪家好
  • 哈尔滨网站开发电话电商培训基地
  • 如何用php数据库做网站搜索seo优化托管
  • 中国城乡建设部人力网站首页优化落实疫情防控
  • 做网站到底能不能赚钱网络优化工程师前景
  • 乌镇网站建设标书百度站长工具域名查询
  • 制作公司网站价格腾讯广告代理商加盟