spring-mvc

Spring-MVC : How to stream mp3 file from controller

。_饼干妹妹 提交于 2021-02-08 04:28:10
问题 I am working on a Spring-MVC application in which I am trying to stream mp3 data. Unfortunately, it's directly triggering a download whenever a byte-array of information is sent in response. I found a few other links, but most of them are tied to an user-interface, so not much useful. What are the requirements for streaming a mp3 file? Here is the download code I have. @RequestMapping(value = "/getsong/{token}") public ResponseEntity<byte[]> getsong(@PathVariable("token") String token,

How to change spring request mapping to disallow url pattern with suffix

我的未来我决定 提交于 2021-02-08 04:21:36
问题 I am using Spring MVC 3.2 and deploying in Apache Tomcat 1.7x. My login url is /web/login but using url /web/login.abc where abc can be any text including space. In both cases it is returning the same resource which I will like to avoid and return HTTP code 404. Tried adding the below in web.xml but it did not help `<beans:bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <beans:property name="useDefaultSuffixPattern" value="false" /> </beans:bean>`

How does Spring get the result from an endpoint that returns CompletableFuture object?

强颜欢笑 提交于 2021-02-07 20:25:23
问题 In the code below, when the endpoint getPerson gets hit, the response will be a JSON of type Person. How does Spring convert CompletableFuture<Person> to Person ? @RestController public class PersonController { @Autowired private PersonService personService; @GetMapping("/persons/{personId}" ) public CompletableFuture<Person> getPerson(@PathVariable("personId") Integer personId) { return CompletableFuture.supplyAsync(() -> personService.getPerson(personId)); } } 回答1: When the

not able to publish custom event in spring before context load

南楼画角 提交于 2021-02-07 20:00:28
问题 I am trying to publish a custom event in Spring MVC, but is is not firing while context is loading, below are the code snippet, The onConnectionOpened will be called after connecting to a server which is triggered after bean initialization using @PostConstruct @Autowired private ApplicationEventPublisher publisher; public void onConnectionOpened(EventObject event) { publisher.publishEvent(new StateEvent("ConnectionOpened", event)); } I am using annotation in listener part as below

not able to publish custom event in spring before context load

给你一囗甜甜゛ 提交于 2021-02-07 19:55:48
问题 I am trying to publish a custom event in Spring MVC, but is is not firing while context is loading, below are the code snippet, The onConnectionOpened will be called after connecting to a server which is triggered after bean initialization using @PostConstruct @Autowired private ApplicationEventPublisher publisher; public void onConnectionOpened(EventObject event) { publisher.publishEvent(new StateEvent("ConnectionOpened", event)); } I am using annotation in listener part as below

SpringBoot app - server context Path

断了今生、忘了曾经 提交于 2021-02-07 19:06:41
问题 I've generated a Spring Boot web application using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file. Technologies used: Spring Boot 2.0.0.M6 , Java 8, maven Here my security config @Override protected void configure(HttpSecurity http) throws Exception { final List<String> activeProfiles = Arrays.asList(env.getActiveProfiles()); if (activeProfiles.contains("dev")) { http.csrf().disable(); http.headers().frameOptions().disable(); } http

Custom WebAuthenticationDetails programmatically in spring security

混江龙づ霸主 提交于 2021-02-07 17:30:03
问题 I am currently moving from an xml-based configuration of spring security to a java based one. I need to setup a custom WebAuthenticationDetails via Java. Is there a way to do that? In XML, I would just set that authenticationDetailsSource of the UsernamePasswordAuthenticationFilter. Relevant sample below <http entry-point-ref="loginUrlAuthenticationEntryPoint"> <custom-filter ref="rememberMeFilter" position="REMEMBER_ME_FILTER"/> <custom-filter ref="loginFilter" position="FORM_LOGIN_FILTER"/>

Custom WebAuthenticationDetails programmatically in spring security

萝らか妹 提交于 2021-02-07 17:29:18
问题 I am currently moving from an xml-based configuration of spring security to a java based one. I need to setup a custom WebAuthenticationDetails via Java. Is there a way to do that? In XML, I would just set that authenticationDetailsSource of the UsernamePasswordAuthenticationFilter. Relevant sample below <http entry-point-ref="loginUrlAuthenticationEntryPoint"> <custom-filter ref="rememberMeFilter" position="REMEMBER_ME_FILTER"/> <custom-filter ref="loginFilter" position="FORM_LOGIN_FILTER"/>

How to access spring session bean scope in thymeleaf

a 夏天 提交于 2021-02-07 17:27:37
问题 I have define my object @Component @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) public class MySession { private String message; // getter setter } When I try to access from thymeleaf it failed. <p th:text="${mySession.message}"></p> SOLUTION Accessing through spring beans http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html <p th:text="${@mySession.getMessage()}"></p> 回答1: session.setAttribute("mySessionAttribute", "someValue"); You can access direct session

Running Spring Webflux Application as a WAR

早过忘川 提交于 2021-02-07 15:14:35
问题 I have a Spring reactive sample application that was modified from one of the examples that was provided in the the Spring Webflux documentation. The master branch of this application uses Spring Boot in the traditional manner, with an embedded application server (Netty). It is working fine. In the Liberty branch, I am trying to build the application as a WAR and deploy to Websphere Liberty Profile. Aside from changes to the build process, the most significant code change is having my