Spring

What is the equivalent of die() in Spring?

二次信任 提交于 2021-02-11 13:00:17
问题 In PHP there is the die("some message"); to write output and stop the execution of the script. So is there an equivalent in Spring mvc ( in Controller and in the JSP ) ? 回答1: There is no reason to have something like die() in Java/JSPs. JSPs should be used as a pure view technology. It should just generate HTML. Not try to access a database, read files or whatnot. That is the job of a controller, written in Java Use System.exit(0); to exit the java code. Keep a note this will stop the JVM

Spring boot JPA many to many with extra column insert and update issue

吃可爱长大的小学妹 提交于 2021-02-11 12:59:24
问题 Here is my initial question. Spring Data JPA Many to Many with extra column User and Roles Now I have the right tables created, but can't make it work for the update. Here is the code: User.java @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String username; @OneToMany(mappedBy="user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List<UserRole> roles; // getters and setters

Which bean is loaded if profile is not set?

假如想象 提交于 2021-02-11 12:47:06
问题 Testing the below Spring profile : <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> <bean id="bean1" class="com.Test2"> </bean> <beans profile="DEV"> <bean id="bean1" class="com.Test1"> </bean> </beans> <bean id="bean1" class="com.Test2"> </bean> </beans> It

spring boot 配置文件加载优先级

牧云@^-^@ 提交于 2021-02-11 12:43:33
Spring Boot 所提供的配置优先级顺序比较复杂。如果Spring Boot在优先级更高的位置找到了配置,那么它就会无视优先级低的配置。按照优先级从高到低的顺序,具体的列表如下所示: 命令行参数。 SpringApplication 类默认会把以“--”开头的命令行参数转化成应用中可以使用的配置参数,如 “--name=Alex” 会设置配置参数 “name” 的值为 “Alex”。如果不需要这个功能,可以通过 “SpringApplication.setAddCommandLineProperties(false)” 禁用解析命令行参数 通过 System.getProperties() 获取的 Java 系统属性。 操作系统环境变量。 从 java:comp/env 得到的 JNDI 属性。 通过 RandomValuePropertySource 生成的“random.*”属性。 应用 Jar 文件之外的属性文件。(通过--spring.config.location参数) 启动Jar包的时候, 指定一个外部配置文件: java -jar demo.jar --spring.config.location=/XXX/XXX.properties 应用 Jar 文件内部的属性文件。 SpringApplication 类会搜索并加载 application

Customize parameters of a step in Spring Batch application

喜你入骨 提交于 2021-02-11 12:41:17
问题 I am working with Spring Batch(using Spring boot). My requirement is to read data from db, process it(validations and stuffs) and write it to a file. I am trying to achieve this using a batch step. Problem is , if i define a step, the reader,processor and writer should be having similar parameters.(from examples i saw and the error i got) Like if my reader is returning a db domain object, the processor and writer should be having domain object parameters. What i am looking for is , reader

Spring XWSS Message Signing

最后都变了- 提交于 2021-02-11 12:41:06
问题 I am currently working on a client interface which connects to a third party web service. This 3rd party web service requires that all messages sent to them are signed with the client's private key. I am attempting to implement this using Spring's XWSS support as documented here: http://docs.spring.io/spring-ws/site/reference/html/security.html The issue I'm facing is that the messages I send out are not being signed despite what as far as I can tell is a correct configuration. My

Customize parameters of a step in Spring Batch application

爱⌒轻易说出口 提交于 2021-02-11 12:40:52
问题 I am working with Spring Batch(using Spring boot). My requirement is to read data from db, process it(validations and stuffs) and write it to a file. I am trying to achieve this using a batch step. Problem is , if i define a step, the reader,processor and writer should be having similar parameters.(from examples i saw and the error i got) Like if my reader is returning a db domain object, the processor and writer should be having domain object parameters. What i am looking for is , reader

404 spring controller error if JSON string contains number greater than 10 digits

送分小仙女□ 提交于 2021-02-11 12:36:44
问题 I'm having a controller which gets json as string in request body as below @PostMapping("/addUser") public ResponseEntity<?> addUser (@RequestBody String userJson,HttpServletRequest request) { log.info("inside add user controller") String responseStatus = serviceInterface.addUser (userJson); return new ResponseEntity (responseStatus); } The request body is { "user": { "username": "testuser", "userId": 12345678901233, "phonenumber": "9876756475", "emailaddress": "test@org.com" } } The problem

Replay Kafka topic with Server-Sent-Events

Deadly 提交于 2021-02-11 12:35:45
问题 I'm thinking about the following use-case and would like to validate if this approach is conceptually valid. The goal is to expose a long-running Server-Sent-Event (SSE) endpoint in Spring replaying the same Kafka topic for each incoming connection (with some user-specific filtering). The SSE is exposed in this way: @GetMapping("/sse") public SseEmitter sse() { SseEmitter sseEmitter = new SseEmitter(); Executors .newSingleThreadExecutor() .execute(() -> dummyDataProducer.generate() // kafka

H2 schema still generated when spring.jpa.generate-ddl=false

大城市里の小女人 提交于 2021-02-11 12:33:32
问题 I am using Spring Boot 2.1.3 with an H2 in memory database for testing. When I run my tests, the schema gets generated even when I specify the following property. spring.jpa.generate-ddl=false It seems that because Spring Boot defaults the following property when using H2 spring.jpa.hibernate.ddl-auto=create-drop That this takes precedence over spring.jpa.generate-ddl=false Is this a bug? 来源: https://stackoverflow.com/questions/55575505/h2-schema-still-generated-when-spring-jpa-generate-ddl