Spring实战(第四版)读书笔记06——配置profile bean并激活profile

    技术2022-07-12  78

    1、在Java中配置profile bean

    使用@Profile("xxx")注解,既可以在配置类级别使用,也可以在方法级别使用,指定profile的bean会在相应profile激活的情况下创建,未指定的始终会被创建。

    2、在XML中配置profile bean

    既可以在根<beans>中通过profile="xxxx"进行配置,也可以在根<beans>中嵌套定义<beans>元素进行配置。

    3、激活profile

    设置spring.profiles.active和spring.profiles.default的多种方式:

    作为DispatcherServlet的初始化参数作为Web应用的上下文参数作为JNDI条目作为环境变量作为JVM的系统属性在集成测试类上,使用@ActiveProfiles注解设置

    可以同时激活多个profile。

    Processed: 0.010, SQL: 9