How to define a List bean in Spring?

I’m using Spring to define stages in my application. It’s configured that the necessary class (here called Configurator) is injected with the stages. Now I need the List of Stages in another class, named LoginBean. The Configurator doesn’t offer access to his List of Stages. I cannot change the class Configurator. My Idea: Define a … Read more

@RequestParam in Spring MVC handling optional parameters

Is it possible for a Spring controller to handle both kind of requests? 1) http://localhost:8080/submit/id/ID123432?logout=true 2) http://localhost:8080/submit/id/ID123432?name=sam&password=543432 If I define a single controller of the kind: @RequestMapping (value = “/submit/id/{id}”, method = RequestMethod.GET, produces=”text/xml”) public String showLoginWindow(@PathVariable(“id”) String id, @RequestParam(value = “logout”, required = false) String logout, @RequestParam(“name”) String username, @RequestParam(“password”) String password, @ModelAttribute(“submitModel”) SubmitModel … Read more

Map enum in JPA with fixed values?

I’m looking for the different ways to map an enum using JPA. I especially want to set the integer value of each enum entry and to save only the integer value. @Entity @Table(name = “AUTHORITY_”) public class Authority implements Serializable { public enum Right { READ(100), WRITE(200), EDITOR (300); private int value; Right(int value) { … Read more

How to POST form data with Spring RestTemplate?

I want to convert the following (working) curl snippet to a RestTemplate call: curl -i -X POST -d “[email protected]” https://app.example.com/hr/email How do I pass the email parameter correctly? The following code results in a 404 Not Found response: String url = “https://app.example.com/hr/email”; Map<String, String> params = new HashMap<String, String>(); params.put(“email”, “[email protected]”); RestTemplate restTemplate = new … Read more

Why does my Spring Boot App always shutdown immediately after starting?

This is my first Spring Boot code. Unfortunately, it always shuts down. I was expecting it to run continuously so that my web client can get some data from the browser. package hello; import org.springframework.boot.*; import org.springframework.boot.autoconfigure.*; import org.springframework.stereotype.*; import org.springframework.web.bind.annotation.*; @Controller @EnableAutoConfiguration public class SampleController { @RequestMapping(“https://stackoverflow.com/”) @ResponseBody String home() { return “Hello World!”; … Read more

Add context path to Spring Boot application

I am trying to set a Spring Boot applications context root programmatically. The reason for the context root is we want the app to be accessed from localhost:port/{app_name} and have all the controller paths append to it. Here is the application configuration file for the web-app. @Configuration public class ApplicationConfiguration { Logger logger = LoggerFactory.getLogger(ApplicationConfiguration.class); … Read more