java高级--SpringBoot篇

目录

一、什么是SpringBoot

        二、SpringBoot的特点

        三、springboot快速入门

        四、介绍配置文件的种类

        五、开发环境配置文件的切换

        六、读取springboot配置文件中的内容

        七、Springboot注册web三大组件

        八、SpringBoot的底层原理

         8.1 包扫描的原理

        8.2  springboot自动装配原理

        九、自定义starter依赖

        9.1 创建一个springboot工程并引入相关得依赖

        9.2 创建一个属性类

        9.3 定义一个业务类

        9.4 定义一个自动装配类

        9.5 在resource下创建一个目录MATE-INF 里面创建一个文件名spring.factories

        9.6 打包--maven 配置了本地仓库

        十、springboot整合数据源

        10.1 引入数据源得启动依赖

        10.2 指定数据源得信息

        10.3 测试

        10.4 springboot整合第三方数据源

        10.5 测试

        十一、springBoot整合Mybatis

        11.1 引依赖

        11.2 修改配置文件

        11.3 写一个实体类(省略)

        11.4 创建Dao接口

        11.5 映射文件

        11.6 在springboot启动类上加上--dao接口得扫描

        11.7 测试---必须为springboot得单元测试【不能使用之前junit得测试】

        十二、springboot整合pageHelper

        十三、springboot整合定时器

        13.1 引入定时器的依赖

        13.2 定义定时器的业务类

        13.3 开启定时器的注解

        十四、 springboot整合swagger2

        14.1 我们如何使用swagger2?   springboot的版本不能那么高。2.2~2.5之间

        14.2 创建一个swagger配置类---所有的功能都集成在Docket类

        14.3 开启swagger2注解

        14.4 定义相关的接口

        14.5 查看swagger2的界面

        14.6 最终的配置类完整格式

         十五、thymeleaf模板引擎


一、什么是SpringBoot

大家想一想,在我们搭建spring应用程序时,你认为什么最麻烦。

  1. 配置xml文件麻烦。---spring的配置文件。web.xml

  2. 很多依赖。

  3. tomcat启动速度很忙。

        Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置【自动装配类】,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。

        二、SpringBoot的特点

(1)可以创建独立的Spring应用程序,并且基于其Maven或Gradle插件,可以创建可执行的JARs和WARs;

(2)内嵌Tomcat或Jetty等Servlet容器;

(3)提供自动配置的“starter”项目对象模型(POMS)以简化Maven配置;

(4)尽可能自动配置Spring容器;--xml配置文件麻烦

(5)提供准备好的特性,如指标、健康检查和外部化配置;

(6)绝对没有代码生成,不需要XML配置。

        三、springboot快速入门

        具备条件:

                        JDK至少1.8以上。

                        maven至少3.2.5以上。

                        开发工具---idea [eclipse]

 

        要把pom文件中的版本号更改

        创建一个HelloController类,该类所在的包必须是主函数下的包或子包下。  

        四、介绍配置文件的种类

        springboot支持两种配置文件的类型:

        第一种: 属性文件[.properties] 格式: key=value

        第二种: yaml文件 [.yml] 格式: 层级关系 key: value

        不管是哪种,他们的前置必须都是application.

        属性文件properties:

# 设置tomcat的端口号
server.port=8888

# 上下文访问路径
server.servlet.context-path=/aaa

        yaml文件:  

# 设置端口号
server:
port: 8887
# 设置上下文路径
servlet:
 context-path: /bbb

        上面两种配置文件可以同时存在,里面的内容如果相同,则properties的优先级高于yaml文件。  

        五、开发环境配置文件的切换

        我们在真实开发过程中:会存在很多环境,而且每个环境他们的配置文件的内容可能不同。

        比如: 开发环境 测试环境 线上环境。

        我就根据不同的环境给出不同的配置内容,你只需要切换环境---即可变成相应环境下的配置。

        定义多个环境下的不同配置文件: application-环境名.properties

        在application.properties配置文件中激活相应的配置

# 引入相关的环境配置--激活开发环境
spring.profiles.active=test
# 写一些不同环境下相同的配置

        六、读取springboot配置文件中的内容

        springboot中提供了两种读取配置文件内容的方式

        第一种: 把读取的内容封装到实体类中

@Autowired
    private AliPay aliPay;
    @RequestMapping("/index")
    public AliPay index(){
        return aliPay;
    }

        测试:

        第二种: 单个属性读取

 

        七、Springboot注册web三大组件

        web三大组件: [1] servlet 、[2] filter、 [3] 监听器 listene

        思考: servlet定义的步骤。

        (1) 创建一个类并继承HttpServlet

        (2) 重写service方法 【doGet 或doPost方法】

      (3)把自定义的servlet注册到web.xml容器中。

        我们现在springboot不存在web.xml文件了。

        注册Servlet组件

public class MyServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~");
    }
}
package com.ykq.config;

import com.ykq.servlet.MyServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpServlet;

@Configuration //====>表示该类为配置类 等价于我们之前的xml文件
public class MyConfig {


    @Bean //xml文件中<bean class=""> 把方法返回的对象交于spring容器来管理
    public ServletRegistrationBean<HttpServlet> registrationBean(){
        ServletRegistrationBean<HttpServlet> servletServletRegistrationBean=new ServletRegistrationBean<>();
        servletServletRegistrationBean.setName("my");
        servletServletRegistrationBean.addUrlMappings("/my");
        servletServletRegistrationBean.setServlet(new MyServlet());
        return servletServletRegistrationBean;
    }
}

        注册Filter组件

        

        步骤: 1.定义一个过滤器类并实现Filter接口

                 2.重写接口中的抽象方法

                 3. 在web.xml文件中注册过滤器。

public class MyFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("过滤器编码");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        
    }
}
    //过滤的注册
    @Bean
    public FilterRegistrationBean<Filter> filterRegistrationBean(){
        FilterRegistrationBean<Filter> filterRegistrationBean=new FilterRegistrationBean<>();
        filterRegistrationBean.setName("encondigFilter");
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setFilter(new MyFilter());
        return filterRegistrationBean;
    }

        八、SpringBoot的底层原理

         8.1 包扫描的原理

        springboot创建的包必须在主类所在的包以及子包下,才可以被容器扫描到。

为什么会在主类所在的包以及子包下扫描?

在主函数中调用run方法,而run方法传递了一个被@SpringBootApplication注解修改的类的反射类对象 该@SpringBootApplication它是复合注解

        @EnableAutoConfiguration 开启自动配置的注解,而该注解也是一个复合注解。

        这里@AutoConfigurationPackage 该注解完成包的自动扫描。  

        通过上面的源码分析 我们得到默认扫描的是主类所在的包以及子包。  

        我们是否可以自定义包扫描。---可以

        8.2  springboot自动装配原理

        思考: 我们并没有配置DispatcherServlet。 为何为拦截请求路径到相应的mapping中。

        因为springboot在启动时会加载一个自动装配类,而这些自动装配会完成相应的自动装配功能。

        流程:

                (1)主函数调用run方法,而run方法加载了一个被@SpringBootApplication注解修饰的类。  

                而该注解是一个复合注解。其中包含@EnableAutoConfiguration该注解可以开启自动装配,而@EnableAutoConfiguration这个也是一个复合注解。其中包含@Import({AutoConfigurationImportSelector.class})而import注解导入了一个AutoConfigurationImportSelector类,该类用来加载需要的自动装配类。而这些自动装配类完成对应的自动装配功能。

        思考: 根据源码 我们看到上来加载了所有的自动装配了,而所有的自动装配类默认127个。这127个从哪来的。  

        分析: 自动装配类如何完成自动装配功能        

        (1)DipatchServletAutoConfiguration [可以完成DispatchServlet的自动装配功能

        发现传递中文没有乱码,而且返回的json数据中也没有出现乱码,因为springboot加载了编码过滤的自动装配了,而这个装配类完成了编码设置的自动装配。  

        九、自定义starter依赖

        如果想自定义Starter,首选需要实现自动化配置,而要实现自动化配置需要满足以下两个条件:

                能够自动配置项目所需要的配置信息,也就是自动加载依赖环境

                能够根据项目提供的信息自动生成Bean,并且注册到Bean管理容器中;

        9.1 创建一个springboot工程并引入相关得依赖

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-autoconfigure</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-configuration-processor</artifactId>
                <optional>true</optional>
            </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

        9.2 创建一个属性类

                作用: 解析springboot配置文件中提供得内容。

/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2022/11/17 14:44
 * @Version 1.0
 */
package com.wjk;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "spring.wjk")
public class WjkProperties {

    private String name;
    private String address;
    private Integer age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

        9.3 定义一个业务类

        作用: 完成相关得业务操作

/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2022/11/17 14:46
 * @Version 1.0
 */
package com.wjk;

public class WjkService {

    private WjkProperties wjkProperties;

    public WjkService() {
    }

    public WjkService(WjkProperties wjkProperties) {
        this.wjkProperties = wjkProperties;
    }

    //业务代码
    public void hello(){
        System.out.println("姓名:"+wjkProperties.getName()+"地址:"+wjkProperties.getAddress()+"年龄:"+wjkProperties.getAge());
    }
}

        9.4 定义一个自动装配类

        完成自动装配得功能。用于完成Bean创建等工作

/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2022/11/17 14:49
 * @Version 1.0
 */
package com.wjk;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration //该类为配置类
@EnableConfigurationProperties(WjkProperties.class) //开启属性配置
@ConditionalOnClass(WjkService.class)  //只要wjkService被引后入,当中的这个类才会被创建
@ConditionalOnProperty(prefix = "spring.wjk",value = "enabled",matchIfMissing = true) //如果引用者没有给定相关的属性值,则采用默认值
public class WjkAutoConfiguration {

    @Autowired
    private WjkProperties wjkProperties;

    @Bean
    @ConditionalOnMissingBean
    public WjkService wjkService(){
        return new WjkService(wjkProperties);
    }

}

        9.5 在resource下创建一个目录MATE-INF 里面创建一个文件名spring.factories

        org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.aaa.YkqAutoConfiguration

        9.6 打包--maven 配置了本地仓库

        打包--maven 配置了本地仓库icon-default.png?t=M85Bhttps://blog.csdn.net/suo_jia_hao/article/details/120759708

        打包成功后,就可以使用一个新的工程,引入自定义的starter的依赖

        以上自定义starter依赖是一个简单的例子

        想看复杂的例子SpringBoot自定义start启动器图文教程(详细)_一个考虑转行送外卖的程序员的博客-CSDN博客

        十、springboot整合数据源

        数据源:指操作数据库

        10.1 引入数据源得启动依赖

        <!--引入数据源依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        10.2 指定数据源得信息

# 指定数据源信息
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=wjk351066

        10.3 测试



@SpringBootTest
@MapperScan(basePackages = "com.wjk.dao")
class Java111501ApplicationTests {

    /**
     * 该依赖自动装配类 帮你建好DataSource对象 交与容器管理
     */
    @Autowired
    private DataSource dataSource;
    @Test
    void contextLoads() {
        System.out.println(dataSource);
    }
}

        10.4 springboot整合第三方数据源

        数据源: springboot默认整合得数据源HikariDataSource. 很多公司使用得可能是其他得数据源。比如Druid数据源 C3p0数据源。

        druid案例提供一个starter依赖。只需要引入该依赖。就会有相应得自动装配。

 <!--引入druid得数据源-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.1</version>
        </dependency>
# 指定数据源信息
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=wjk351066
spring.datasource.druid.initial-size=5
spring.datasource.druid.max-active=10

        10.5 测试

@SpringBootTest
class Qy158Springboot01ApplicationTests {

    //数据源对象---自己有没有创建该类对象---因为你引入spring-boot-starter-jdbc启动依赖。
    //该依赖得自动装配类 帮你创建好DataSource对象 交于容器管理
    @Autowired
    private DataSource dataSource;
    @Test
    void contextLoads() throws SQLException {
        System.out.println(dataSource);
    }

}

 

        十一、springBoot整合Mybatis

        11.1 引依赖

        <!--mybatis得整合启动依赖-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.0</version>
        </dependency>

        11.2 修改配置文件

# 指定mybatis得配置内容
mybatis.mapper-locations=classpath:/mapper/*.xml
# 指定mybatis
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

        11.3 写一个实体类(省略)

        11.4 创建Dao接口

package com.wjk.dao;

import com.wjk.entity.Student;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
public interface StudentDao {

    public List<Student> selectAll();


     int insert(Student student);

     int delete(Integer id);

     int update(Student student);
}

        11.5 映射文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wjk.dao.StudentDao">
    <insert id="insert">
        insert into t_student values (null ,#{name},#{age},#{address})
    </insert>

    <update id="update">
        update t_student set name =#{name},age=#{age},address=#{address} where id=#{id}
    </update>

    <delete id="delete">
        delete from t_student where id=#{id}
    </delete>

    <select id="selectAll" resultType="com.wjk.entity.Student">
        select * from t_student
    </select>

</mapper>

        11.6 在springboot启动类上加上--dao接口得扫描

        11.7 测试---必须为springboot得单元测试【不能使用之前junit得测试】

    @Resource
    private StudentDao studentDao;
    @Test
    void testSelectAll(){
        PageHelper.startPage(1,3);
        List<Student> list = studentDao.selectAll();
        System.out.println(list);
    }

        十二、springboot整合pageHelper

  <!--pagehelper分页插件得依赖-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.4.2</version>
        </dependency>
@Resource
    private StudentDao studentDao;
    @Test
    void testSelectAll(){
        PageHelper.startPage(1,3);
        List<Student> list = studentDao.selectAll();

        PageInfo<Student> pageInfo = new PageInfo<>(list);
        System.out.println("总条数:"+pageInfo.getTotal());
        System.out.println("当前页的条数:"+pageInfo.getList());
    }

        十三、springboot整合定时器

        什么是定时器?  在指定的时间间隔内执行相关的任务。

        应用场景:

                比如: 未支付取消订单。

                定时删除OSS中冗余的文件。

                注册成功后,在七天发送短信问候。

        13.1 引入定时器的依赖

   <!--引入定时器的依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-quartz</artifactId>
        </dependency>

        13.2 定义定时器的业务类

             在线Cron表达式生成器的链接: 在线Cron表达式生成器

package com.wjk.quartz;


import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component //交与容器管理
public class MyQuartz {

    /**
     * 业务代码 Scheduled规定什么时候执行业务代码
     */
    @Scheduled(cron = "0/5 * * * * ? ")
    public void test(){
        System.out.println("********************");
    }
}

        13.3 开启定时器的注解

        十四、 springboot整合swagger2

        什么是swagger2?   使用Swagger开源和专业工具集简化用户、团队和企业的API开发。了解Swagger如何帮助您大规模设计和记录API文档

        为什么使用API文档?

 

        14.1 我们如何使用swagger2?   springboot的版本不能那么高。2.2~2.5之间

 <!--引入swagger2的依赖-->
        <dependency>
            <groupId>com.spring4all</groupId>
            <artifactId>swagger-spring-boot-starter</artifactId>
            <version>1.9.1.RELEASE</version>
        </dependency>

        <!--swagger图形化界面-->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>swagger-bootstrap-ui</artifactId>
            <version>1.9.6</version>
        </dependency>

        14.2 创建一个swagger配置类---所有的功能都集成在Docket类

@Configuration  //标记为配置类
public class SwaggerConfig {

    @Bean
    public Docket docket(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2)

        return docket;
    }
}

        14.3 开启swagger2注解

package com.wjk;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableScheduling //开启定时器注解
@EnableSwagger2 //开启swagger2的注解
public class SpringBoot1118Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringBoot1118Application.class, args);
    }

}

        14.4 定义相关的接口

@RestController
public class HelloController {


    @GetMapping("hello01")
    public String hello01(){
        return "hello01";
    }
}

        14.5 查看swagger2的界面

        14.6 最终的配置类完整格式

/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2022/11/18 10:06
 * @Version 1.0
 */
package com.wjk.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

@Configuration  //标记为配置类
public class SwaggerConfig {

    @Bean
    public Docket docket(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                //组名
                .groupName("wjk")
                //api信息
                .apiInfo(getInfo())
                //选择哪些生成api接口--根据请求路径选择 (2)根据包名选择
                .select()
                //根据请求路径选择
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                //根据报名选择
                .apis(RequestHandlerSelectors.basePackage("com.wjk.controller"))
                .build()
                ;
        return docket;
    }


    private ApiInfo getInfo(){
        Contact DEFAULT_CONTACT = new Contact("王俊凯", "http://www.jd.com", "1315272325@qq.com");
        ApiInfo info = new ApiInfo("在线预约挂号系统", "在线挂号系统", "9.9", "http://www.baidu.com",
                DEFAULT_CONTACT, "上海富有银行有限公司", "http://www.taobao.com", new ArrayList<VendorExtension>());
        return info;
    }
}

        我们还有另外一个网址  更简洁更容易看懂  http://localhost:port/doc.html         

 

介绍: swagger常用的注解

  • @Api:修饰整个类,描述Controller的作用

  • @ApiOperation:描述一个类的一个方法,或者说一个接口

  • @ApiImplicitParam:一个请求参数

  • @ApiImplicitParams:多个请求参数

  • @ApiModel:用对象来接收参数

  • @ApiModelProperty:用对象接收参数时,描述对象的一个字段

         十五、thymeleaf模板引擎

        就是一个网页模板【jsp 现在不能使用jsp的原因:springboot中内置的tomcat 不支持jsp模板引擎】。

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
@RestController
public class PageController {

    @RequestMapping("/index")
    public String index(){
        return "index";
    }
}

 

        Thymeleaf_洋葱爱代码的博客-CSDN博客_thymeleaf   具体使用请看文档  懒得写了

  • 18
    点赞
  • 86
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
Java中,使用Spring Boot时,自动装配是一个非常重要的功能。通过自动装配,Spring Boot可以根据项目的依赖和配置,自动加载相应的类和配置,简化了开发过程。在Spring Boot中,自动装配是通过引入相应的依赖来实现的。例如,如果你想在Spring Boot中使用JDBC和MySQL,你可以在pom.xml文件中添加以下依赖: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> ``` 这样,当Spring Boot启动时,它会自动加载与JDBC和MySQL相关的自动配置类。这些自动配置类会根据项目的配置文件和依赖,自动配置数据库连接等相关功能。这样,你就可以在项目中直接使用JDBC和MySQL,而无需手动配置和加载相关类。\[1\] 需要注意的是,Spring Boot的自动装配是基于Spring Framework的自动装配功能进行的。Spring Boot只是在Spring Framework的基础上进行了进一步的优化和简化。因此,你可以在Spring Boot中使用Spring Framework的自动装配接口规范来进行自定义的自动装配。\[2\] 如果你在使用Spring Boot时遇到了无法自动装配的问题,可能是由于以下原因: 1. 依赖缺失:你可能没有正确引入相关的依赖。请检查你的pom.xml文件,确保所有必要的依赖都已经添加。 2. 配置错误:你可能没有正确配置相关的属性或配置文件。请检查你的配置文件,确保所有必要的属性都已经配置正确。 3. 自定义配置冲突:你可能在自己的代码中进行了自定义的配置,与自动装配的配置发生了冲突。请检查你的代码,确保自定义的配置与自动装配的配置兼容。 如果以上方法都无法解决问题,你可以尝试查看Spring Boot的日志输出,以获取更详细的错误信息。另外,你也可以参考Spring Boot的官方文档和社区论坛,寻求更多的帮助和解决方案。\[3\] #### 引用[.reference_title] - *1* [JAVA高级--springboot自动装配](https://blog.csdn.net/lpt1314/article/details/125943497)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Springboot自动装配](https://blog.csdn.net/xyy1028/article/details/130933835)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [springBoot自动装配](https://blog.csdn.net/qq_62898618/article/details/127883716)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值