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. evevt

    EventEvent 是一个事件对象,当一个事件发生后,和当前事件发生相关的详细信息会被临时存储到一个指定的地方,也就是event对象,以方便我们在需要的时候调用. 在这一点上,非常类似于飞机当中的黑 ...

  2. linux 网络基础之IP地址

    IP是英文Internet Protocol的缩写,意思是“网络之间互连的协议”,也就是为计算机网络相互连接进行通信而设计的协议. IP地址类型分为:公有地址.私有地址. 公有地址 公有地址(Publ ...

  3. Delphi - Indy 创建邮件自动发送服务

    服务器自动邮件线程 功能:此程序主要实现对Oracle数据库表tableName(存放需要发送邮件的相关信息)里面相关信息的邮件发送. 优点:开发人员可以直接再数据库后台对tableName表进行插入 ...

  4. Linux下手动安装JDK

    一.删除自带的JDK 查询系统自带JDK rpm -qa | grep java rpm -qa | grep jdk 删除查询出来的文件名 rpm -e --nodeps 文件名 命令执行成功后重新 ...

  5. set和push方法压入栈顶的值获取方法

    向值栈里面放数据(储存的位置在root域里面) 向值栈放数据有多种方式,往往我们只用其中一种 1.set方法压栈 1)在Action中获取值栈对象,使用set()方法向值栈存放数据 ActionCon ...

  6. HDU 5984 题解 数学推导 期望

    Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decorative s ...

  7. Java NIO 下

    内存映射文件 JAVA处理大文件,一般用BufferedReader,BufferedInputStream这类带缓冲的IO类,不过如果文件超大的话,更快的方式是采用MappedByteBuffer. ...

  8. CodeForces Round #498 div3

    A: 题目没读, 啥也不会的室友帮我写的. #include<bits/stdc++.h> using namespace std; #define Fopen freopen(" ...

  9. codeforces 766 D. Mahmoud and a Dictionary(种类并查集+stl)

    题目链接:http://codeforces.com/contest/766/problem/D 题意:给你n个单词,m个关系(两个单词是反义词还是同义词),然后问你所给的关系里面有没有错的,最后再给 ...

  10. hdu 2844 Coins 多重背包(模板) *

    Coins                                                                             Time Limit: 2000/1 ...