原文:spring启动时通过指定profile加载不同的bean

有时候我们有多个环境,开发环境 测试环境 生产环境,每个环境都有不同的配置信息 如何用一套代码,在不同环境上都能运行,spring的profile就是用来解决这个问题 比如想着测试环境加载一个配置类,那么这个类可以加上这个注解 一 命令行和 Profile注解用法 在运行jar包时只需要使用如下命令,就可以加载这个对象 Profile修饰类 Profile修饰方法 参考:https: blog.c ...

2021-04-28 13:09 0 258 推荐指数:

查看详情

spring启动时指定启动

有时候我们在项目里有这样的需求,不在pom文件指定主类,而是在启动时指定主类,这个我研究了半天,发现可用实现,记录一下 有这么几个点需要关注: 1.pom打包的配置 要么指定mainClass,要不就把layout设定为ZIP,里面的原理有机会再深入了解 2.代码中 ...

Wed Apr 28 19:43:00 CST 2021 0 518
spring boot 项目在启动时执行指定sql文件

参考博客: https://www.jianshu.com/p/88125f1cf91c 1. 启动时执行 当有在项目启动时先执行指定的sql语句的需求,可以在resources文件夹下添加需要执行的sql文件,文件中的sql语句可以是DDL脚本或DML脚本,然后在配置加入 ...

Sun Apr 14 05:15:00 CST 2019 0 3592
spring注解之@PostConstruct在项目启动时执行指定方法

一、注解解释 Spring的@PostConstruct注解在方法上,表示此方法是在Spring实例化该Bean之后马上执行此方法,之后才会去实例化其他Bean,并且一个Bean中@PostConstruct注解的方法可以有多个。 二、示例代码 1. spring配置文件 ...

Wed Apr 24 04:48:00 CST 2019 0 11354
基于spring的web项目启动时加载数据到ServletContext

1、要在web启动时加载数据到ServletContext,实现方法有很多,一种比较简单的方案就是:   1)新建一个bean,定义其初始化方法:     <bean id="beanId" class="beanClassName" init-method="初始化方法" /> ...

Thu Mar 14 09:03:00 CST 2019 0 1375
Spring Boot学习--项目启动时执行指定service的指定方法

Springboot给我们提供了两种“开机启动”某些方法的方式:ApplicationRunner和CommandLineRunner。 这两种方法提供的目的是为了满足,在项目启动的时候立刻执行某些方法。我们可以通过实现ApplicationRunner和CommandLineRunner ...

Thu May 24 01:56:00 CST 2018 0 4320
spring-boot:run启动时指定spring.profiles.active

Maven启动指定Profile通过-P,如mvn spring-boot:run -Ptest,但这是Maven的Profile。 如果要指定spring-boot的spring.profiles.active,则必须使用mvn spring-boot:run -Drun.profiles ...

Mon Oct 23 17:10:00 CST 2017 0 12095
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM