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

做网站一般用什么系统app网站开发培训

做网站一般用什么系统,app网站开发培训,网站建设套餐介绍,网站推广方法有几个越来越方便了 java技术生态发展近25年,框架也越来越方便使用了,简直so easy!!!我就以Spring衍生出的Spring boot做演示,Spring boot会让你开发应用更快速。 快速启动spring boot 请参照官网 Spring | Quic…

越来越方便了

 java技术生态发展近25年,框架也越来越方便使用了,简直so easy!!!我就以Spring衍生出的Spring boot做演示,Spring boot会让你开发应用更快速。

快速启动spring boot 请参照官网 Spring | Quickstart

代码如下:

@SpringBootApplication
@RestController
public class SpringBootTestApplication {public static void main(String[] args) {SpringApplication.run(SpringBootTestApplication.class, args);}@GetMapping("/hello")public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {return String.format("Hello %s!", name);}
}

注maven的pom文件 (部分):

 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId><scope>provided</scope>
</dependency>

运行

通过浏览器方法http://localhost:8080/hello

至此一个简单的spring boot应用开发完毕,要是公司企业的展示性网站用这种方式极快。

我们重点关注一下这个@SpringBootApplication注解,就是因为它,程序运行主类,相当于跑了一个tomcat中间件,既然能通过web访问,说明是一个web应用程序。

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
/*** Exclude specific auto-configuration classes such that they will never be applied.* @return the classes to exclude*/@AliasFor(annotation = EnableAutoConfiguration.class)Class<?>[] exclude() default {};/*** Exclude specific auto-configuration class names such that they will never be* applied.* @return the class names to exclude* @since 1.3.0*/@AliasFor(annotation = EnableAutoConfiguration.class)String[] excludeName() default {};/*** Base packages to scan for annotated components. Use {@link #scanBasePackageClasses}* for a type-safe alternative to String-based package names.* <p>* <strong>Note:</strong> this setting is an alias for* {@link ComponentScan @ComponentScan} only. It has no effect on {@code @Entity}* scanning or Spring Data {@link Repository} scanning. For those you should add* {@link org.springframework.boot.autoconfigure.domain.EntityScan @EntityScan} and* {@code @Enable...Repositories} annotations.* @return base packages to scan* @since 1.3.0*/@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")String[] scanBasePackages() default {};/*** Type-safe alternative to {@link #scanBasePackages} for specifying the packages to* scan for annotated components. The package of each class specified will be scanned.* <p>* Consider creating a special no-op marker class or interface in each package that* serves no purpose other than being referenced by this attribute.* <p>* <strong>Note:</strong> this setting is an alias for* {@link ComponentScan @ComponentScan} only. It has no effect on {@code @Entity}* scanning or Spring Data {@link Repository} scanning. For those you should add* {@link org.springframework.boot.autoconfigure.domain.EntityScan @EntityScan} and* {@code @Enable...Repositories} annotations.* @return base packages to scan* @since 1.3.0*/@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")Class<?>[] scanBasePackageClasses() default {};......略了
}

发现@SpringBootApplication注解是一个组合型注解,有3个Spring annotations:@SpringBootConfiguration, @ComponentScan, and @EnableAutoConfiguration ,记住@EnableAutoConfiguration注解很重要,其次@ComponentScan注解。

@EnableAutoConfiguration注解,spring boot 会基于classpath路径的jar、注解和配置信息,会自动配置我们的应用程序,所有的这些注解会帮助spring boot 自动配置我们的应用程序,我们不必担心配置它们。我演示的代码,spring boot会检查classpath路径,由于有依赖spring-boot-starter-web,Spring boot会把项目配置成web应用项目,另外Spring Boot将把它的HelloController当作一个web控制器,而且由于我的应用程序依赖于Tomcat服务器(spring-boot-starter-tomcat),Spring Boot也将使用这个Tomcat服务器来运行我的应用程序。

特别注意,框架里是否装载Bean会配合条件表达式一起使用

 真正使用时是混合使用的

@EnableAutoConfiguration代码:

package org.springframework.boot.autoconfigure;@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";/*** Exclude specific auto-configuration classes such that they will never be applied.* @return the classes to exclude*/Class<?>[] exclude() default {};/*** Exclude specific auto-configuration class names such that they will never be* applied.* @return the class names to exclude* @since 1.3.0*/String[] excludeName() default {};}

又有两个需要理解的元注解meta-annotation : @AutoConfigurationPackage 和@Import(AutoConfigurationImportSelector.class)

@AutoConfigurationPackage代码:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import(AutoConfigurationPackages.Registrar.class)
public @interface AutoConfigurationPackage {String[] basePackages() default {};Class<?>[] basePackageClasses() default {};
}

这个注解又用了一个@Import, 它的value值是:  AutoConfigurationPackages.Registrar.class.,而

AutoConfigurationPackages.Registrar 实现ImportBeanDefinitionRegistrar。还记得我以前写的博文Spring Bean注册的几种方式Spring Bean注册的几种方式_filterregistrationbean beandefinitionregistrypostp_董广明的博客-CSDN博客吗

@Import(AutoConfigurationImportSelector.class)

这个注解是自动配置机制,AutoConfigurationImportSelector实现了 DeferredImportSelector.

这个选择器的实现使用spring core功能方法:SpringFactoriesLoader.loadFactoryNames() ,该方法从META-INF/spring.factories加载配置类

而这个引导配置类从spring-boot-autoconfigure-2.3.0.RELEASE-sources.jar!/META-INF/spring.factories文件加载,该文件有键org.springframework.boot.autoconfigure.EnableAutoConfiguration

注意spring引导自动配置模块隐式包含在所有引导应用程序中。

参考:

  1. SpringBoot中@EnableAutoConfiguration注解的作用  SpringBoot中@EnableAutoConfiguration注解的作用_51CTO博客_@enableautoconfiguration注解报错

  2. Talking about how Spring Boot works  Talking about how Spring Boot works - Huong Dan Java

  3. How Spring Boot Works? Spring Boot Rock’n’Roll -王福强的个人博客:一个架构士的思考与沉淀
  4.  How Spring Boot auto-configuration works  How Spring Boot auto-configuration works | Java Development Journal
  5. Spring Boot - How auto configuration works? https://www.logicbig.com/tutorials/spring-framework/spring-boot/auto-config-mechanism.html
  6. SpringBoot 启动原理  SpringBoot 启动原理 | Server 运维论坛

  7. How SpringBoot AutoConfiguration magic works? https://www.sivalabs.in/how-springboot-autoconfiguration-magic/

  8. @EnableAutoConfiguration Annotation in Spring Boot @EnableAutoConfiguration Annotation in Spring Boot
http://www.yayakq.cn/news/347798/

相关文章:

  • 教育海报设计素材网站网站怎样关键词排名优化
  • 深圳国税局网站怎么做票种核定网店代运营网
  • 域名注册成功后怎么使用网站js网站计数器代码
  • 铁岭网络推广网站建设微信网站开发文档
  • 网站建设的经费估算网络营销实际上就是网上营销
  • 东莞市官网网站建设iss怎么做网站
  • 高并发网站建设做一个同城便民信息网站怎么做
  • 网站重构案例深圳菜谱制作
  • 如何建立一个网站卖货一家做土产网站
  • 用手机做自己的网站网站前置审核申请报告
  • dede网站建设很卡wordpress文章怎么生成标签
  • 杭州制造业企业做网站做商城网站设计
  • 海口企业自助建站百度智能建站适合优化吗
  • php网站开发背景介绍十个有趣又好玩的网页
  • 宁波网站建设服务商建站模板有哪些
  • 万网空间官方网站做家政下载什么网站或什么群呢
  • 深圳专业设计网站平台怎样做企业的网站建设
  • 广东佛山最新通知seo上首页
  • 公司网站开发模板画册设计一般用什么软件
  • 苏州北京商场网站建设网站模板修改工具
  • 正一品网站建设logo标志设计网
  • 服装网站建设基本流程工商局网站怎么做股东实名认证
  • 热烈祝贺网站上线大连宏帝建设网站
  • cps网站建设南通通明建设监理有限公司网站
  • 衡阳商城网站制作网站卖链接
  • 毛网商城石家庄seo网站管理
  • 建设网站0基础需要学什么开一个网站建设公司需要什么软件
  • 广州网站排名推广wordpress添加icon文件
  • 郑州市东区建设环保局官方网站建站模板推荐
  • 网上做家教的网站顶客网站和网摘网站