修改maven地址
修改maven地址 在setting maven中设置,选择overwrite ,去到对应的文件夹下面创建settings文件
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
第一个SpringBoot程序
创建第一个Springboot
在pom.xml中添加
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
在Application同級目录下创建Controller文件夹创建一个测试类Hello,暂时不管注解的含义
@Controller
@RequestMapping("/hello")
public class HelloController {
@GetMapping("/hello")
@ResponseBody
public String hello(){
return "hello";
}
}
重新启动项目,在localhost:8080/hello/hello看到启动成功输出hello
改端口
在resources下的application.properties
server.port=8081
自动配置
pom.xml
- 标签内点进去有大量的jar包
- 有大量的启动器
- 我们写或者引入springBoot依赖的时候,不需要指定版本,因为有版本仓库
启动器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- 实际上就是SpringBoot的启动场景;例如
spring-boot-starter-web,他就会帮我们导入web环境的所有依赖
-
SpringBoot将所有的功能场景,变成一个个的启动器
点开依赖查看jar包,有如下几个我们认识的
<activemq.version>5.15.11</activemq.version>//消息队列
<db2-jdbc.version>11.5.0.0</db2-jdbc.version>//数据库
<ehcache.version>2.10.6</ehcache.version>
<ehcache3.version>3.8.1</ehcache3.version>//缓存
需要声明功能就start启动哪个模块,
进入spring官网https://docs.spring.io/spring-boot/docs/2.2.5.RELEASE/reference/html/using-spring-boot.html#using-boot-starter查看功能对应的启动器
主程序
//标注这个类是一个SpringBoot应用
@SpringBootApplication
public class Class1Application {
public static void main(String[] args) {
//将Spring应用启动
SpringApplication.run(Class1Application.class, args);
}
}
-
注解
-
@SpringBootConfiguration //SpringBoot的配置 @Configuration:spring配置类 @Component:这是一个spring组件 @EnableAutoConfiguration :自动配置 @AutoConfigurationPackage:自动配置包 @Import({Registrar.class}):导入选择器