草庐IT

spring-boot-project

全部标签

java - 如何在 Spring Boot 应用程序启动时启动 H2 TCP 服务器?

通过将以下行添加到SpringBootServletInitializermain方法中,我可以在将应用程序作为SpringBoot应用程序运行时启动H2TCP服务器(文件中的数据库):@SpringBootApplicationpublicclassNatiaApplicationextendsSpringBootServletInitializer{publicstaticvoidmain(String[]args){Server.createTcpServer().start();SpringApplication.run(NatiaApplication.class,args)

java - spring - 从 application.properties 文件中读取环境变量

我在application.properties文件中指定了Spring属性。我如何从环境变量中填充这些属性?这是我试过的,但似乎不起作用:application.propertiesspring.datasource.url=jdbc:postgresql://#{systemProperties['DATABASE_HOST']}:5432/dbnamespring.datasource.username=postgresspring.datasource.password=postgres 最佳答案 您可以像使用${...}语

java - 删除然后创建记录导致Spring Data JPA重复 key 冲突

因此,在这种情况下,我需要记录头记录,删除它的详细信息,然后以其他方式重新创建详细信息。更新细节将带来太多麻烦。我基本上有:@Transactionalpublicvoidcreate(Integerid,ListcustomerIDs){Headerheader=headerService.findOne(id);//headerisfound,hasmultipledetails//Removethedetailsfor(Detaildetail:header.getDetails()){header.getDetails().remove(detail);}//Iterateth

java - 在自己的线程中运行每个 Spring Scheduler

我有多个带有@Scheduled注释的组件,我看到Spring一次只启动一个组件,即使它们被安排在同一时间运行也是如此。我的用例如下。我希望每个@Scheduled注释在其自己的线程中运行,但每个线程只运行一次。给定这个带有两个调度程序的伪代码:@Scheduled(cron="0*****")//runeveryminutepublicvoidmethodA(){log.info("RunningmethodA");executeLongRunningJob("FinishedmethodA");}@Scheduled(cron="0*****")//runeveryminutepu

java - Spring Data REST - 如何在投影中包含计算数据?

我定义了以下域类。贷款类别@Data@EntitypublicclassLoan{@Id@GeneratedValue(strategy=GenerationType.IDENTITY)privatelongid;privateStringloanTitle;@OneToMany(cascade=CascadeType.ALL,orphanRemoval=true)@JoinColumn(name="loan_id")privateListallowances;}津贴等级@Data@EntitypublicclassAllowance{@Id@GeneratedValue(strate

java - JPMS/Project Jigsaw 对小型应用程序/库的好处

我了解Java平台模块系统(JPMS)对大型应用程序的好处,但是否有任何理由将小型库或应用程序制作成(单个)模块?如果是这样,是ModularJarFiles实现此目的的最佳方法,还是首选常规方法?展望future,模块化v.classpath程序是否会对性能产生影响? 最佳答案 直接的性能影响包括以下内容:模块化应用程序可以选择使用jlink这样可分发运行时的大小就减小了:它只使用你需要的模块。因此,如果您不需要Swing、Corba等,它不会驻留在磁盘上。(更多信息here)。模块化应用程序使用模块图进行类加载;该算法比类路径的

java - spring 拦截器不向@RestController 服务添加 header

我有以下拦截器:publicclassSecurityInterceptorextendsHandlerInterceptorAdapter{@OverridepublicvoidpostHandle(HttpServletRequestrequest,HttpServletResponseresponse,Objecthandler,ModelAndViewmodelAndView)throwsException{response.addHeader("X-Frame-Options","DENY");}}我检查过-spring在每个http请求上调用它。我注意到一件奇怪的事。它适用

java - 通过 spring rest 模板获取异常的堆栈跟踪

我有2个服务-Service1和Service2。Service1通过SpringRestTemplate调用一些Service2API。现在Service2中发生了一些异常。我需要它在Service1中的整个堆栈跟踪。如何获取?Service1---calls-->Service2堆栈跟踪甚至会被Spring传递给Service1吗?你可以说我是这样打电话的:HttpHeadersheaders=newHttpHeaders();headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));HttpEntityentity=

java - Spring 启动 : 404 error when calling JSP using controller

使用SpringToolSuite运行我的项目时出现以下错误,但万一我的问题是我已经将适当的依赖项添加到pom.XML文件中。那么可能是什么问题呢?我的pom.XML文件依赖如下,org.apache.tomcat.embedtomcat-embed-jasperprovidedorg.springframework.bootspring-boot-starter-tomcat2.1.3.RELEASE我的ControllerApplicationController.java如下,packagecom.example.demo.controller;importorg.springf

java - Junit4 + Spring 2.5 : Asserts throw "NoClassDefFoundError"

我一直在使用Spring在Junit4中编写测试代码,我得到了这个有趣的行为:如果我的测试是这样通过的,那么一切都很好:@TestpublicvoidtruthTest(){assertTrue(true);//Ok}但是,如果我的测试失败了:@TestpublicvoidtruthTest(){assertTrue(false);//ERROR}然后我收到了一个丑陋而神秘的堆栈跟踪,而不是测试失败,就是这样:http://pastie.org/429912对于这个丑陋的转储感到抱歉,但这是我必须解释问题的唯一数据(为了便于阅读,我“粘贴”了它)我真的很纳闷,有没有人遇到过这种问题?提