[英]How to execute spring-boot:run from terminal for Remote Debugging
[英]How to execute postgres sql block from spring-boot
我必须从spring启动应用程序执行一个sql脚本块(通常是一个函数)。 我不能将此功能保留在我的postgres数据库中,因为我想在应用程序级别维护。 我尝试使用schema.sql
(来自资源文件夹),这看起来像只在服务器启动期间执行。
但是我想在每次需要时通过JPA或JDBCTemplate调用这个plsql块。
schema.sql
除了可以按需执行之外的任何其他选择吗?
在单元测试中有@Sql注释,您可以使用它来执行脚本:
@RunWith(SpringRunner.class)
@SpringBootTest
@Sql("/reset_sequences.sql")
public class ModuleTemplateRepositoryTests { ... }
为了从spring应用程序启动自定义sql脚本,我们使用ScriptUtils ( 此处为stackoverflow)
@Value("classpath:reset_sequences.sql")
Resource script;
@Autowired
JdbcTemplate jdbcTemplate;
...
ScriptUtils.executeSqlScript(
jdbcTemplate.getDataSource().getConnection(), script);
如果您将函数存储在数据库中,则可以在此处查看此示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.