• Spring Boot之@ImportResource、配置类、占位符表达式


    一、@ImportResource

       spring boot自动装配/自动配置

        Spring 扥配置文件 默认会被spring boot自动给配置好。

        如果要自己编写spring等配置文件,spring boot能否识别?

        当然是可以的。

    在resources目录下创建spring.xml文件。

    <bean id="studentService" class="com.doublechen.helloworld.service.StudentService"></bean>
    

      在主配置类application.java中:

      

    @ImportResource(locations={"classpath:spring.xml"})
    

      加入注解,标明配置文件就可以使用自己配置的文件了。

    但是这种手动配置不推荐使用。我们可以使用创建配置类的形式代替写配置文件。

    AppConfig.class:

    package com.doublechen.helloworld.conf;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    import com.doublechen.helloworld.service.StudentService;
    
    @Configuration
    public class AppConfig {
    	
    	@Bean
    	public StudentService studentService(){
    		StudentService studentService = new StudentService();
    		return studentService;//相当于:<bean id="studentService" class="com.doublechen.helloworld.service.StudentService"></bean>
    
    	}
    }
    

      

    占位符表达式:

  • 相关阅读:
    线程的创建和运行
    Spring SpringMvc Mybatis Maven整合
    使用 Redis 缓存来实现用户最近浏览的商品列表
    Java泛型
    HDFS的HA集群原理分析
    MapReduce-自动化运行配置
    大数据-HDFS 集群搭建的配置文件
    鼠标线状移动特效
    Mac 终端 Tomcat 环境配置过程
    oracle列转行
  • 原文地址:https://www.cnblogs.com/jccjcc/p/14179472.html
Copyright © 2020-2023  润新知