1. Spring boot 对代码结构无特殊要求,但有个套最佳实践的推荐
    1. 不要使用没有包名的类。没有包名时,@ComponentScan, @EntityScan, or @SpringBootApplication 可能会有问题。
    2. Main类在包路径中的位置:强烈建议main类放在包的根路径上。We generally recommend that you locate your main application class in a root package above other classes. The @SpringBootApplication annotation is often placed on your main class, and it implicitly defines a base “search package” for certain items. For example, if you are writing a JPA application, the package of the @SpringBootApplication annotated class is used to search for @Entity items. Using a root package also allows component scan to apply only on your project.
      1. com
        +- example
        +- myapplication
        +- Application.java
        |
        +- customer
        | +- Customer.java
        | +- CustomerController.java
        | +- CustomerService.java
        | +- CustomerRepository.java
        |
        +- order
        +- Order.java
        +- OrderController.java
        +- OrderService.java
        +- OrderRepository.java
    3. The Application.java file would declare the main method, along with the basic @SpringBootApplication, as follows:
      1. package com.example.myapplication;
        
        import org.springframework.boot.SpringApplication;
        import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
        public class Application { public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        } }
    4. @RestController
      @EnableAutoConfiguration
      public class App
      {
      @RequestMapping("/hello")
      public HashMap<String,String> hello(){
      HashMap<String,String> result=new HashMap<String,String>();
      result.put("name", "jt");
      return result; }
      public static void main( String[] args )
      {
      SpringApplication.run(App.class, args);
      }
      }

Spring boot 梳理 - 代码结构(Main类的位置)的更多相关文章

  1. spring boot 结合Redis 实现工具类

    自己整理了 spring boot 结合 Redis 的工具类引入依赖 <dependency> <groupId>org.springframework.boot</g ...

  2. Spring Boot@Component注解下的类无法@Autowired的问题

    title: Spring Boot@Component注解下的类无法@Autowired的问题 date: 2019-06-26 08:30:03 categories: Spring Boot t ...

  3. spring boot修改代码后无需重启设置,在开发时实现热部署

    Spring Boot在开发时实现热部署(开发时修改文件保存后自动重启应用)(spring-boot-devtools) 热部署是什么 大家都知道在项目开发过程中,常常会改动页面数据或者修改数据结构, ...

  4. spring boot 文件上传工具类(bug 已修改)

    以前的文件上传都是之前前辈写的,现在自己来写一个,大家可以看看,有什么问题可以在评论中提出来. 写的这个文件上传是在spring boot 2.0中测试的,测试了,可以正常上传,下面贴代码 第一步:引 ...

  5. Spring boot 梳理 - WebMvcConfigurer接口 使用案例

    转:https://yq.aliyun.com/articles/617307 SpringBoot 确实为我们做了很多事情, 但有时候我们想要自己定义一些Handler,Interceptor,Vi ...

  6. Spring boot 梳理 - @Conditional

    @Conditional(TestCondition.class) 这句代码可以标注在类上面,表示该类下面的所有@Bean都会启用配置,也可以标注在方法上面,只是对该方法启用配置. spring框架还 ...

  7. Spring boot 梳理 -@SpringBootApplication、@EnableAutoConfiguration与(@EnableWebMVC、WebMvcConfigurationSupport,WebMvcConfigurer和WebMvcConfigurationAdapter)

    @EnableWebMvc=继承DelegatingWebMvcConfiguration=继承WebMvcConfigurationSupport 直接看源码,@EnableWebMvc实际上引入一 ...

  8. spring boot的项目结构问题

    问题:spring boot项目能够正常启动,但是在浏览器访问的时候会遇到404的错误,Whitelable Error Page 404 分析及解决方案:首先Application文件要放在项目的外 ...

  9. Spring boot 梳理 - 模版引擎 -freemarker

    开发环境中关闭缓存 spring: thymeleaf: cache: false freemarker: cache: false Spring boot 集成 freemarker <dep ...

随机推荐

  1. python批量处理压缩文件

    python批量处理压缩文件 博客小序:在数据的处理中,下载的数据很有可能是许多个压缩文件,自己一个一个解压较为麻烦,最近几日自己在处理一次下载的数据时,遇到大量的压缩数据需要处理,于是利用pytho ...

  2. python3 统计类的实例个数

    python3 统计类的实例个数 有时候我们可能想统计下类所创建的实例个数,代码如下: class Dog: # 定义一个狗类 count = 0 # 用于统计类所创建的实例个数 def __init ...

  3. 安装Python及各种包/库——没有网络的电脑上

    我们做项目时可能会遇到,一些电脑只能联内网或者无法联网,这种情况怎样在电脑上安装Python及各种第三方包/库呢? 1.首先,在有网络的电脑上在python官网下载好python安装包,地址:http ...

  4. Windows上提高工作效率的神器推荐

    Everything 下载地址:http://www.voidtools.com/ 功能:硬盘文件搜索,比起电脑自带的文件搜索,效率提高不是一丁半点.而且Everything还支持正则表达式,小巧而快 ...

  5. 带你了解什么是Push消息推送

    前言 只有光头才能变强. 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 如果有看我最近文章的同学可能就知道我在公司负责的是一 ...

  6. ASP.NET Core 3.0中使用动态控制器路由

    原文:Dynamic controller routing in ASP.NET Core 3.0 作者:Filip W 译文:https://www.cnblogs.com/lwqlun/p/114 ...

  7. lightoj 1057 - Collecting Gold(状压dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1057 题解:看似有点下记忆话搜索但是由于他是能走8个方向的也就是说两点的距离其 ...

  8. lightoj 1049 - One Way Roads(dfs)

    Time Limit: 0.5 second(s) Memory Limit: 32 MB Nowadays the one-way traffic is introduced all over th ...

  9. Kafka中的ISR、AR又代表什么?ISR的伸缩又指什么?

    相信大家已经对 kafka 的基本概念已经有一定的了解了,下面直接来分析一下 ISR 和 AR 的概念. ISR and AR 简单来说,分区中的所有副本统称为 AR (Assigned Replic ...

  10. Java日志之Slf4j,Log4J,logback原理总结

    几乎任何应用,一定是需要日志的. 那么,面对种类繁多的日志框架和配置,我们该何去何从? 1.前奏:我是在研究mybatis源码的过程中才意识到需要搞明白日志原理这回事,因为mybatis(和一些其他开 ...