初学Springboot

===========================================编写HelloSpringboot========================================

  1. 编写时pom.xml添加parent,有的公司自己封装一个包用parent供pom.xml继承
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.5</version>
</parent>
  • 而后加入一个依赖 
<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>2.3.5.RELEASE</version>
</dependency>

2.写一个main方法直接启动springboot

//@SpringBootApplication 这是一个springboot应用
@SpringBootApplication
public class HelloSpringBoot {
    public static void main(String[] args) {
        SpringApplication.run(HelloSpringBoot.class, args);
    }
}

​

3.写一个controller测试,并且重启springboot

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String handle01(){
        return "Hello,Spring Boot 2!";
    }
}

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Apr 25 14:14:48 CST 2021

There was an unexpected error (type=Not Found, status=404).

问题可能是:

  1. 代码放在启动类同级目录或下级目录中。
  2. 启动类使用@SpringBootApplication注解。
  3. controller中缺少@Controller或者@RestController注解。
  4. 无法访问静态资源。
  5. 查看配置文件中是否配置context-path,若配置,请求访问的时候就需要加上该路径。

大量简化配置,全部配置集中在application.properties文件中

配置的参数文档

https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#common-application-properties

=====================================maven工程打包并且部署=====================================

  • 修改package

  • 增加build
 <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

问题:idea 项目的target目录不见了,但是show in explorer可以找到,很不方便。
原因:此文件被忽略了

解决:两种情况

1.设置忽略

2.project视图设置->showExcludeFiles

找到target下的jar包

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值