zoukankan      html  css  js  c++  java
  • 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>
    
    	}
    }
    

      

    占位符表达式:

  • 相关阅读:
    自适应网页设计?
    布局设置加版心?
    bootstrap框架使用?
    Electron框架下,如何使用jquery?
    轮播插件swiper.js?
    表格出现滚动条设置?
    overflow问题--滚动设置?
    移动端页面适配ipad?
    移动端页面构建需注意?
    复杂的Sql分组
  • 原文地址:https://www.cnblogs.com/jccjcc/p/14179472.html
Copyright © 2011-2022 走看看