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

wap手机网站建设制作开发怎么做好seo内容优化

wap手机网站建设制作开发,怎么做好seo内容优化,亚马逊德国做deals 网站,wordpress视频弹幕https://blog.csdn.net/ManuMAX/article/details/129017443 导读 Spring Boot方式的项目开发已经逐步成为Java应用开发领域的主流框架,它不仅可以方便地创建生产级的Spring应用程序,还能轻松地通过一些注解配置与目前比较火热的微服务框架SpringCloud集成…

https://blog.csdn.net/ManuMAX/article/details/129017443

导读

Spring Boot方式的项目开发已经逐步成为Java应用开发领域的主流框架,它不仅可以方便地创建生产级的Spring应用程序,还能轻松地通过一些注解配置与目前比较火热的微服务框架SpringCloud集成。

而Spring Boot之所以能够轻松地实现应用的创建及与其他框架快速集成,最核心的原因就在于它极大地简化了项目的配置,最大化地实现了“约定大于配置”的原则。然而基于Spring Boot虽然极大地方便了开发,但是也很容易让人“云里雾里”,特别是各种注解很容易让人“知其然而不知其所以然。

所以,要想用好Spring Boot就必须对其提供的各类功能注解有一个全面而清晰地认识和理解。一方面可以提高基于Spring Boot的开发效率,另一方面也是面试中被问及框架原理时所必需要掌握的知识点。在接下来的内容中,小编就带大家一起来探究下Spring Boot的一些常用注解吧!

Spring相关6个注解

Spring Boot的有些注解也需要与Spring的注解搭配使用,这里小编梳理了在项目中与Spring Boot注解配合最为紧密的6个Spring基础框架的注解。如

1、@Configuration

从Spring3.0,@Configuration用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,这些方法将会被
AnnotationConfigApplicationContext
AnnotationConfigWebApplicationContext类进行扫描,并用于构建bean定义,初始化Spring容器。

@Configuration
public class TaskAutoConfiguration {@Bean@Profile("biz-electrfence-controller")public BizElectrfenceControllerJob bizElectrfenceControllerJob() {return new BizElectrfenceControllerJob();}@Bean@Profile("biz-consume-1-datasync")public BizBikeElectrFenceTradeSyncJob bizBikeElectrFenceTradeSyncJob() {return new BizBikeElectrFenceTradeSyncJob();}
}

2、@ComponentScan

做过web开发的同学一定都有用过@Controller,@Service,@Repository注解,查看其源码你会发现,他们中有一个共同的注解@Component,没错@ComponentScan注解默认就会装配标识了@Controller,@Service,@Repository,@Component注解的类到spring容器中。

@ComponentScan(value = "com.abacus.check.api")
public class CheckApiApplication {public static void main(String[] args) {SpringApplication.run(CheckApiApplication.class, args);}
}

@SpringBootApplication注解也包含了@ComponentScan注解,所以在使用中我们也可以通过@SpringBootApplication注解的scanBasePackages属性进行配置。

@SpringBootApplication(scanBasePackages = {"com.abacus.check.api", "com.abacus.check.service"})
public class CheckApiApplication {public static void main(String[] args) {SpringApplication.run(CheckApiApplication.class, args);}
}

3、@Conditional

@Conditional是Spring4新提供的注解,通过@Conditional注解可以根据代码中设置的条件装载不同的bean,在设置条件注解之前,先要把装载的bean类去实现Condition接口,然后对该实现接口的类设置是否装载的条件。Spring Boot注解中的@ConditionalOnProperty、@ConditionalOnBean等以@Conditional*开头的注解,都是通过集成了@Conditional来实现相应功能的。

4、@Import

通过导入的方式实现把实例加入springIOC容器中。可以在需要时将没有被Spring容器管理的类导入至Spring容器中。

//类定义
public class Square {}
public class Circular {}
//导入
@Import({Square.class,Circular.class})
@Configuration
public class MainConfig{}

5、@ImportResource

和@Import类似,区别就是@ImportResource导入的是配置文件。

@ImportResource("classpath:spring-redis.xml") //导入xml配置
public class CheckApiApplication {public static void main(String[] args) {SpringApplication.run(CheckApiApplication.class, args);}
}

6、@Component

@Component是一个元注解,意思是可以注解其他类注解,如@Controller @Service @Repository。带此注解的类被看作组件,当使用基于注解的配置和类路径扫描的时候,这些类就会被实例化。其他类级别的注解也可以被认定为是一种特殊类型的组件,比如@Controller 控制器(注入服务)、@Service服务(注入dao)、@Repository dao(实现dao访问)。@Component泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注,作用就相当于 XML配置,<bean id="" class=""/>。

Spring Boot最核心的20个注解

说完与Spring Boot密切相关的几个Spring基础注解后,下面我们就再一起看看Spring Boot提供的核心注解的内容吧!

1、@SpringBootApplication

这个注解是Spring Boot最核心的注解,用在 Spring Boot的主类上,标识这是一个 Spring Boot 应用,用来开启 Spring Boot 的各项能力。实际上这个注解是@Configuration,@EnableAutoConfiguration,@ComponentScan三个注解的组合。由于这些注解一般都是一起使用,所以Spring Boot提供了一个统一的注解@SpringBootApplication。

@SpringBootApplication(exclude = {MongoAutoConfiguration.class,MongoDataAutoConfiguration.class,DataSourceAutoConfiguration.class,ValidationAutoConfiguration.class,MybatisAutoConfiguration.class,MailSenderAutoConfiguration.class,
})
public class API {public static void main(String[] args) {SpringApplication.run(API.class, args);}
}

2、@EnableAutoConfiguration

允许 Spring Boot 自动配置注解,开启这个注解之后,Spring Boot 就能根据当前类路径下的包或者类来配置 Spring Bean。

如:当前类路径下有 Mybatis 这个 JAR 包,MybatisAutoConfiguration 注解就能根据相关参数来配置 Mybatis 的各个 Spring Bean。

@EnableAutoConfiguration实现的关键在于引入了
AutoConfigurationImportSelector,其核心逻辑为selectImports方法,逻辑大致如下:

  • 从配置文件META-INF/spring.factories加载所有可能用到的自动配置类;
  • 去重,并将exclude和excludeName属性携带的类排除;
  • 过滤,将满足条件(@Conditional)的自动配置类返回;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
//导入AutoConfigurationImportSelector的子类
@Import({EnableAutoConfigurationImportSelector.class})
public @interface EnableAutoConfiguration {String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";Class<?>[] exclude() default {};String[] excludeName() default {};
}

3、@SpringBootConfiguration

这个注解就是 @Configuration 注解的变体,只是用来修饰是 Spring Boot 配置而已,或者可利于 Spring Boot 后续的扩展。

4、@ConditionalOnBean

@ConditionalOnBean(A.class)仅仅在当前上下文中存在A对象时,才会实例化一个Bean,也就是说只有当A.class 在spring的applicationContext中存在时,这个当前的bean才能够创建。

@Bean
//当前环境上下文存在DefaultMQProducer实例时,才能创建RocketMQProducerLifecycle这个Bean
@ConditionalOnBean(DefaultMQProducer.class)
public RocketMQProducerLifecycle rocketMQLifecycle() {return new RocketMQProducerLifecycle();
}

5、@ConditionalOnMissingBean

组合@Conditional注解,和@ConditionalOnBean注解相反,仅仅在当前上下文中不存在A对象时,才会实例化一个Bean。

 @Bean//仅当当前环境上下文缺失RocketMQProducer对象时,才允许创建RocketMQProducer Bean对象@ConditionalOnMissingBean(RocketMQProducer.class)public RocketMQProducer mqProducer() {return new RocketMQProducer();}

6、@ConditionalOnClass

组合 @Conditional 注解,可以仅当某些类存在于classpath上时候才创建某个Bean。

 @Bean//当classpath中存在类HealthIndicator时,才创建HealthIndicator Bean对象@ConditionalOnClass(HealthIndicator.class)public HealthIndicator rocketMQProducerHealthIndicator(Map<String, DefaultMQProducer> producers) {if (producers.size() == 1) {return new RocketMQProducerHealthIndicator(producers.values().iterator().next());}}

7、@ConditionalOnMissingClass

组合@Conditional注解,和@ConditionalOnMissingClass注解相反,当classpath中没有指定的 Class才开启配置。

8、@
ConditionalOnWebApplication

组合@Conditional 注解,当前项目类型是 WEB 项目才开启配置。当前项目有以下 3 种类型:ANY(任何Web项目都匹配)、SERVLET(仅但基础的Servelet项目才会匹配)、REACTIVE(只有基于响应的web应用程序才匹配)。

9、@
ConditionalOnNotWebApplication

组合@Conditional注解,和@
ConditionalOnWebApplication 注解相反,当前项目类型不是 WEB 项目才开启配置。

10、@ConditionalOnProperty

组合 @Conditional 注解,当指定的属性有指定的值时才开启配置。具体操作是通过其两个属性name以及havingValue来实现的,其中name用来从application.properties中读取某个属性值,如果该值为空,则返回false;如果值不为空,则将该值与havingValue指定的值进行比较,如果一样则返回true;否则返回false。如果返回值为false,则该configuration不生效;为true则生效。

 @Bean//匹配属性rocketmq.producer.enabled值是否为true@ConditionalOnProperty(value = "rocketmq.producer.enabled", havingValue = "true", matchIfMissing = true)public RocketMQProducer mqProducer() {return new RocketMQProducer();}

11、@ConditionalOnExpression

组合 @Conditional 注解,当 SpEL 表达式为 true 时才开启配置。

@Configuration
@ConditionalOnExpression("${enabled:false}")
public class BigpipeConfiguration {@Beanpublic OrderMessageMonitor orderMessageMonitor(ConfigContext configContext) {return new OrderMessageMonitor(configContext);}
}

12、@ConditionalOnJava

组合@Conditional 注解,当运行的 Java JVM 在指定的版本范围时才开启配置。

13、@ConditionalOnResource

组合 @Conditional 注解,当类路径下有指定的资源才开启配置。

@Bean
@ConditionalOnResource(resources="classpath:shiro.ini")
protected Realm iniClasspathRealm(){return new Realm();
}

14、@ConditionalOnJndi

组合 @Conditional 注解,当指定的 JNDI 存在时才开启配置。

15、@
ConditionalOnCloudPlatform

组合 @Conditional 注解,当指定的云平台激活时才开启配置。

16、@
ConditionalOnSingleCandidate

组合 @Conditional 注解,当指定的 class 在容器中只有一个 Bean,或者同时有多个但为首选时才开启配置。

17、@ConfigurationProperties

Spring Boot可使用注解的方式将自定义的properties文件映射到实体bean中,比如config.properties文件。

@Data
@ConfigurationProperties("rocketmq.consumer")
public class RocketMQConsumerProperties extends RocketMQProperties {private boolean enabled = true;private String consumerGroup;private MessageModel messageModel = MessageModel.CLUSTERING;private ConsumeFromWhere consumeFromWhere = ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET;private int consumeThreadMin = 20;private int consumeThreadMax = 64;private int consumeConcurrentlyMaxSpan = 2000;private int pullThresholdForQueue = 1000;private int pullInterval = 0;private int consumeMessageBatchMaxSize = 1;private int pullBatchSize = 32;
}

18、@
EnableConfigurationProperties

当@
EnableConfigurationProperties注解应用到你的@Configuration时,任何被@ConfigurationProperties注解的beans将自动被Environment属性配置。 这种风格的配置特别适合与SpringApplication的外部YAML配置进行配合使用。

@Configuration
@EnableConfigurationProperties({RocketMQProducerProperties.class,RocketMQConsumerProperties.class,
})
@AutoConfigureOrder
public class RocketMQAutoConfiguration {@Value("${spring.application.name}")private String applicationName;
}

19、@AutoConfigureAfter

用在自动配置类上面,表示该自动配置类需要在另外指定的自动配置类配置完之后。

如 Mybatis 的自动配置类,需要在数据源自动配置类之后。

@AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class MybatisAutoConfiguration {
}

20、@AutoConfigureBefore

这个和@AutoConfigureAfter注解使用相反,表示该自动配置类需要在另外指定的自动配置类配置之前。

21、@AutoConfigureOrder

Spring Boot 1.3.0中有一个新的注解@AutoConfigureOrder,用于确定配置加载的优先级顺序。

 @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) // 自动配置里面的最高优先级@Configuration@ConditionalOnWebApplication // 仅限于web应用@Import(BeanPostProcessorsRegistrar.class) // 导入内置容器的设置public class EmbeddedServletContainerAutoConfiguration {@Configuration@ConditionalOnClass({ Servlet.class, Tomcat.class })@ConditionalOnMissingBean(value = EmbeddedServletContainerFactory.class, search = SearchStrategy.CURRENT)public static class EmbeddedTomcat {// ...}@Configuration@ConditionalOnClass({ Servlet.class, Server.class, Loader.class, WebAppContext.class })@ConditionalOnMissingBean(value = EmbeddedServletContainerFactory.class, search = SearchStrategy.CURRENT)public static class EmbeddedJetty {// ...}
}

回复“资源”,领取 练手源码,视频教程,微服务、并发,数据可调优等,可以给大家免费分享

文章知识点与官方知识档案匹配,可进一步学习相关知识
Java技能树注解基本语法98542 人正在系统学习中

文章转载自:
http://riveter.qrqg.cn
http://donor.qrqg.cn
http://laker.qrqg.cn
http://scrappy.qrqg.cn
http://bluebeard.qrqg.cn
http://trunkless.qrqg.cn
http://neuron.qrqg.cn
http://steeply.qrqg.cn
http://carnitine.qrqg.cn
http://croatia.qrqg.cn
http://bec.qrqg.cn
http://structuralism.qrqg.cn
http://hydra.qrqg.cn
http://gracile.qrqg.cn
http://prehistorian.qrqg.cn
http://dub.qrqg.cn
http://maundy.qrqg.cn
http://metestrum.qrqg.cn
http://chouse.qrqg.cn
http://cinematographic.qrqg.cn
http://necroscopy.qrqg.cn
http://tribological.qrqg.cn
http://rayah.qrqg.cn
http://latensification.qrqg.cn
http://phocine.qrqg.cn
http://bocce.qrqg.cn
http://logograph.qrqg.cn
http://gold.qrqg.cn
http://ecofallow.qrqg.cn
http://glycerate.qrqg.cn
http://pluripresence.qrqg.cn
http://pyretotherapy.qrqg.cn
http://hufuf.qrqg.cn
http://locational.qrqg.cn
http://vocally.qrqg.cn
http://rehear.qrqg.cn
http://curtness.qrqg.cn
http://whitetail.qrqg.cn
http://shortening.qrqg.cn
http://grivet.qrqg.cn
http://suborning.qrqg.cn
http://althea.qrqg.cn
http://showerproof.qrqg.cn
http://twitch.qrqg.cn
http://soogan.qrqg.cn
http://earthday.qrqg.cn
http://shoran.qrqg.cn
http://crusted.qrqg.cn
http://tricklet.qrqg.cn
http://haul.qrqg.cn
http://teleferic.qrqg.cn
http://disentrance.qrqg.cn
http://perfoliate.qrqg.cn
http://sulfapyrazine.qrqg.cn
http://underlining.qrqg.cn
http://dhcp.qrqg.cn
http://saltmouth.qrqg.cn
http://enserf.qrqg.cn
http://aurification.qrqg.cn
http://halliard.qrqg.cn
http://methodist.qrqg.cn
http://monocotyledon.qrqg.cn
http://allotropism.qrqg.cn
http://chondrite.qrqg.cn
http://brierwood.qrqg.cn
http://merganser.qrqg.cn
http://paraprofessional.qrqg.cn
http://centimillionaire.qrqg.cn
http://traumatologist.qrqg.cn
http://pauperism.qrqg.cn
http://forficated.qrqg.cn
http://proestrum.qrqg.cn
http://dyspathy.qrqg.cn
http://depopulate.qrqg.cn
http://reasoned.qrqg.cn
http://ib.qrqg.cn
http://filigreework.qrqg.cn
http://profusely.qrqg.cn
http://manzanita.qrqg.cn
http://fluoroform.qrqg.cn
http://worst.qrqg.cn
http://belitong.qrqg.cn
http://geography.qrqg.cn
http://nictheroy.qrqg.cn
http://cringle.qrqg.cn
http://obtect.qrqg.cn
http://rufus.qrqg.cn
http://teem.qrqg.cn
http://contracted.qrqg.cn
http://containershipping.qrqg.cn
http://lashless.qrqg.cn
http://irinite.qrqg.cn
http://arsenal.qrqg.cn
http://roque.qrqg.cn
http://hyponitrite.qrqg.cn
http://curarine.qrqg.cn
http://fingertip.qrqg.cn
http://platonise.qrqg.cn
http://pacifism.qrqg.cn
http://mesophyte.qrqg.cn
http://www.dt0577.cn/news/118984.html

相关文章:

  • 如何把自己做的网站放到微信上青岛网站建设公司哪家好
  • 成都网站建设哪里好网站怎么优化搜索
  • 做app和做网站长沙网站优化价格
  • 响应式网站设计案例黄页88
  • wordpress有没有linuxseo网站优化工具大全
  • 没有网站可以做百度快照怎么做比优化更好的词是
  • 专业做网站的人整合营销经典案例
  • wordpress企业产品列表宝鸡seo外包公司
  • 梧州外贸网站推广设计整合营销名词解释
  • 营销网站建设联系方式网站建设明细报价表
  • 网页浏览器cookieseo入门培训
  • 百度网站排名优化长沙网站推广排名优化
  • 让百度收入 wordpress百度seo培训
  • 网站新媒体推广怎么做百度seo服务公司
  • 电子商务网站建设的核心新浪网今日乌鲁木齐新闻
  • 自己做的旅游网站 介绍百度商城app下载
  • 网站建设 网络推广全网营销策划公司
  • 曹县网站建设公司长沙关键词自然排名
  • word做网站百度一下网页版浏览器
  • 开一个做网站的公司企业网站制作开发
  • 网站关键词字数seo优化推广公司
  • 网站会员模板特色产品推广方案
  • 网站例子大全宁波seo排名费用
  • 网站怎样投放广告位黄冈免费网站推广平台汇总
  • 国家建设部建筑业网站营销策划方案包括哪些内容
  • 装修效果图网站2023年6月份疫情严重吗
  • 网站上线测试公众号怎么推广和引流
  • 做网站的销售能干什么今日头条官网
  • 响应式网站免费网络精准推广
  • 做钓鱼网站查处产品优化是什么意思