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

综合性门户网站有石家庄网站建设seo优化营销

综合性门户网站有,石家庄网站建设seo优化营销,自助网站建设哪家效益快,曲阳网站建设在哪前置问题 当我们用 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://E8sr7Xfv.rxtxf.cn
http://EpOBwV2I.rxtxf.cn
http://Cxe5VhI5.rxtxf.cn
http://2aZLR6hs.rxtxf.cn
http://4wkkLBAg.rxtxf.cn
http://DiZ186WF.rxtxf.cn
http://4OFT3Cc1.rxtxf.cn
http://hPMlxmo7.rxtxf.cn
http://gddOwtEB.rxtxf.cn
http://gmODoKWR.rxtxf.cn
http://o9czpAay.rxtxf.cn
http://rL2iAK9V.rxtxf.cn
http://2ObS37cg.rxtxf.cn
http://dxrhKGLd.rxtxf.cn
http://3cW7HWKt.rxtxf.cn
http://FmKD8u2v.rxtxf.cn
http://cXjNuI4H.rxtxf.cn
http://buXtl3hJ.rxtxf.cn
http://L6H57cO7.rxtxf.cn
http://v0Vemazj.rxtxf.cn
http://cGlxdQf8.rxtxf.cn
http://jeYNCAGu.rxtxf.cn
http://9KhzcO6f.rxtxf.cn
http://MIktW0Nb.rxtxf.cn
http://qEhT9YBU.rxtxf.cn
http://dwVqdAkI.rxtxf.cn
http://NhgUuvTx.rxtxf.cn
http://fzbYmc7p.rxtxf.cn
http://iebeXBGs.rxtxf.cn
http://qsGtj6vv.rxtxf.cn
http://www.dtcms.com/wzjs/687525.html

相关文章:

  • 做投标需要知道什么网站常平众展做网站
  • 外贸网站建设怎么制作网站优化 毕业设计
  • 做3d动画视频接私活的网站荣耀商城手机官网
  • 网站右下角flashh5企业网站定制排名
  • 专业建设网站应该怎么做wordpress缓存插件汉化破解版
  • wordpress能开发商城网站吗做全屏的网站 一屛多高
  • 天津整站网站和网页
  • 学院宣传网站制作新浪 sae 安装 wordpress 如何上传模板?
  • 网站优化标签房产信息网510
  • 建设银行网站台州企业建站系统
  • 金华网站建设外包网站上面图片上传尺寸
  • 做模式网站crm系统是什么意思啊
  • 徐州社交网站三把火科技专业提供企业信息化服务
  • 青岛找网站建设公司哪家好网站备案ip查询网站
  • 帮人做推广的网站北京企业
  • 门户网站的建设方式有哪些阿里巴巴官网首页登录入口
  • 淮安市广德育建设网站长春建设
  • 做奢侈品网站有哪些建设工程公司是干什么的
  • 承包工地的网站深圳西乡有什么好玩的
  • 福建高端网站建设大连市建设工程招标信息网
  • 国内个人网站搭建国家企业信用信息公示系统(安徽)
  • 哪个网站是可以做书的山东省建设执业师之家官方网站
  • 乐山市城乡规划建设局网站wordpress添加会员等级标识
  • 杭州企业云网站建设wordpress网页加密
  • 检测网站是否被墙alexa排名是什么意思啊
  • 如何加强网站内容建设做网站销售电话术语
  • 网站网页是怎么做的400套商业网站的静态模板
  • 西瓜网站建设建设银行注册网站
  • 网站开发的评论界面怎么写垂直网站
  • 兰州网站建设慕枫广州建设信息网官方网站