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

深圳专业建站多少钱线上渠道推广

深圳专业建站多少钱,线上渠道推广,wordpress搜索全站,建设网站要多少页面前置问题 当我们用 compoent 注解时,注解需要被 Spring的组件扫描扫描到。SpringBootApplication 具有包扫描的作用 ,但是扫描范围只有当前包及其子包 列子 MvcConfig 这个配置类需要在 user-service 中使用。我们启动 user-service 会报扫描不到 MvcCon…

前置问题

当我们用 @compoent 注解时,注解需要被 Spring的组件扫描扫描到。@SpringBootApplication 具有包扫描的作用 ,但是扫描范围只有当前包及其子包

列子

MvcConfig 这个配置类需要在 user-service 中使用。我们启动 user-service 会报扫描不到 MvcConfig 这个配置类

在这里插入图片描述
在这里插入图片描述

解决办法

第一种:直接使用 @ComponentScan 组件扫描


在引用了配置类的类的启动类中使用 @ComponentScan 手动扫描
注意自己默认的扫描会被覆盖。所以要手动加入自己默认的扫描,也就是当前包及子包

因为麻烦,性能差所以不推荐

  • UserApplication
@ComponentScan(basePackages = {"com.hmall.common.config", "com.hmall.user"})
public class UserApplication {public static void main(String[] args) {SpringApplication.run(UserApplication.class, args);}
}

第二种:使用 @Import 直接导入


  • UserApplication
@Import(MvcConfig.class)
@SpringBootApplication
public class UserApplication {public static void main(String[] args) {SpringApplication.run(UserApplication.class, args);}
}

第三种:@Import 导入 ImportSelector 接口实现类


  • hm-common 中定义 ImportSelector 实现类
public class MyImportSelector implements ImportSelector {public String[] selectImports(AnnotationMetadata importingClassMetadata) {return new String[] {"com.example.HeaderConfig"};//把要放入 IOC 容器中的全类名放进去}
}
  • user-service 的启动类中 @Import 导入
@SpringBootApplication
@Import(MyImportSelector.class)
public class UserApplication {public static void main(String[] args) {SpringApplication.run(UserApplication.class, args);}}

第四种:直接写入 META-INF 自动配置文件


  • SpringBoot2META-INF/spring.factories
  • SpringBoot3META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

这里以 SpringBoot2 为例

  • META-INF/spring.factories

SpringBoot 已启动就会读取这里的列出的类。自动加载到 IOC 中,即使这些配置类所在的包不在扫描范围内

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.hmall.common.config.MyBatisConfig,\com.hmall.common.config.JsonConfig,\//这里新增了 MvcConfigcom.hmall.common.config.MvcConfig
  • 我们也可以限制什么时候自动加载这个类

使用 ConditionalOnClass。这里就是只有在 SpringMVC 环境下才加载,在其他环境不加载例如响应式环境

@Configuration
@ConditionalOnClass(DispatcherServlet.class)
public class MvcConfig implements WebMvcConfigurer {@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(new UserInfoInterceptor());}
}
http://www.dtcms.com/a/554004.html

相关文章:

  • ROS开发中`laser_scan_matcher`节点启动失败问题的分析与解决
  • 南昌装修网站建设菠菜网站的代理怎么做
  • c++调用客户端库与kafka交互
  • 用Liunx service方式管理SuperMap iServer
  • 邢台网站设计哪家专业wordpress主题添加后台设置选项
  • 京东网站建设的策划书如何做120急救网站
  • 佛山新网站建设服务安卓开发是做什么的
  • 普通园区摄像头如何将视频传输至云端平台
  • HDMI接口与串口:核心知识点解析及全方位区别对比
  • sql server 备份恢复全备和日志备份时间相近恢复失败
  • 回溯剪枝trick
  • 网页设计与制作用什么软件做北京公司排名seo
  • 什么伪原创网站好深圳全面放开
  • 【.NET】依赖注入浅显解释
  • IDEA连接MySQL服务器数据库指南
  • 设计模式——builder生成器模式
  • 政务公开与网站建设工作总结存在问题和困难小程序装修页面设计
  • 厦门网站网站建设php wordpress 模版
  • Python爬虫---中国大学MOOC爬取数据(文中有
  • Nginx 从零到精通 - 最详细的循序渐进教程
  • Rust专项——迭代器高级用法:flat_map、fold、并行迭代与性能优化
  • 阿里云wordpress建站找做网站的公司
  • 做招聘网站赚钱吗用c 做网站
  • kafka添加压缩配置后失败
  • 深入理解网络层:互联网的 “交通指挥中心“ 与核心技术解析
  • webrtc代码走读(十三)-QOS-帧率调控机制
  • 【机器学习10】项目生命周期、偏斜类别评估、决策树
  • Linux驱动开发与Android驱动开发
  • 在Ubuntu云服务器上安装宝塔面板的完整指南
  • 网站的运营维护南京h5网站开发