spring-mvc

SpringBoot: Bypass OncePerRequestFilter filters

别等时光非礼了梦想. 提交于 2020-01-23 02:16:07
问题 I have a basic SpringBoot 2.0.5.RELEASE app. Using Spring Initializer, JPA, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file. I have created a Custom JWT based security filter JwtFilter : @Provider public class JwtAuthorizationTokenFilter extends OncePerRequestFilter { ... } But I want to Bypass this filter only for 1 specific request / method: "/api/v1/menus" , when is a POST But I don't know if it is possible in the WebSecurityConfigurerAdapter :

Failing to @AutoWire a member in a @WebServlet

回眸只為那壹抹淺笑 提交于 2020-01-23 02:01:45
问题 I can't seem to get my servlet's fields to @AutoWire; they end up null. I have a pure annotation-configured webapp (no XML files). My servlet looks like this: @WebServlet("/service") public class SatDBHessianServlet extends HttpServlet { @Autowired protected NewsItemDAO mNewsItemDAO; } Other @AutoWired things seem to work fine, both @Service objects and @Repository objects. But not this one, and I can't figure out why. I even tried adding its package to the ComponentScan(basePackages) list

Spring REST service not consuming JSON

♀尐吖头ヾ 提交于 2020-01-23 01:57:10
问题 I am having some difficulty using Spring's built-in JSON consumption using Jackson with REST web services. If I define the following: ... @RequestMapping(value="/stub") public void doSomething(@RequestBody User user) { System.err.println("In method"); ... } ... it never reaches the method. I have Jackson in the classpath. However, when I manually use Jackson: @RequestMapping(value="/stub") public void doSomething(@RequestBody String user) { System.err.println("In method"); User newUser = null

How to setup Spring Logs for Tomcat

时间秒杀一切 提交于 2020-01-23 01:04:31
问题 Working on Spring MVC and not having Spring logs has made it hard to debug. I have read few other articles on this problem and none seem to help me. log4j.properties is in src folder. slf4j-api-1.5.11 , slf4j-log4j12-1.5.11 , slf4j-simple-1.5.11 , commons-logging-1.1.jar and log4j-1.2.16.jar jars are in the classpath. Log4j content is: log4j.rootLogger=INFO, console # Console appender log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j

How to fix Fortify Race Condition: Singleton Member Field issue

六眼飞鱼酱① 提交于 2020-01-22 20:47:09
问题 I encounter a problem. we use Spring MVC framework in my Project,but Spring MVC default Controller is Singleton Model. I change Controller use @Scope("session") by session to avoid race Condition problem(everyone has own Controller). @Controller @Scope("session") public class AP0Controller extends BaseController { @Autowired GnRecService gnRecService; Integer seq = null;//Global variable @RequestMapping(value = "/agn/AP1W01A_004", method=RequestMethod.GET) public ModelAndView welcomeGrid(

Validation for generated JAXB Classes (JSR 303 / Spring)

…衆ロ難τιáo~ 提交于 2020-01-22 19:22:27
问题 I Generated domain objects from schema (request & response) using JAXB (maven-jaxb2-plugin) I would like add validations (notnull /empty) for couple of attributes. I would like to have custom Bean Validation, the application is a REST service, i'm using Spring 3 and JSR 303 but i dont think i can use JSR 303 to validate the object as it is generated from the schema. can someone give me a nudge in the right direction on how to get this done. 回答1: We've been using the Krasa JAXB plugin to

Java Spring: Real-time status update to the client over REST API

自作多情 提交于 2020-01-22 14:19:11
问题 I am developing a web application in Java Spring where I want the user to be able to upload a CSV file from the front-end and then see the real-time progress of the importing process and after importing he should be able to search individual entries from the imported data. The importing process would consist of actually uploading the file (sending it via REST API POST request) and then reading it and saving its contents to a database so the user would be able to search from this data. How

Spring Boot classpath

六月ゝ 毕业季﹏ 提交于 2020-01-22 08:47:52
问题 In the Spring Boot's docs here, about serving static content, it says: By default Spring Boot will serve static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath . I found that all the content in the directory: src/main/resources will be copied inside the classpath , so I can put my static content in: src/main/resources/static and all will work fine and I'm happy since I can have my static content under the src directory. But, I have

ModelAndView.addObject vs Model.addAttribute

て烟熏妆下的殇ゞ 提交于 2020-01-22 08:04:56
问题 Good day, I'm learning Spring MVC and I'm writting my tiny webapp following this tutorial but I slightly modified it as a "list of tasks" and not "list of users". One thing is not clear to me so I'd like to ask for an explanation. This is my edit.jsp: <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%> <html> <head> <title>Edit task<

ModelAndView.addObject vs Model.addAttribute

风格不统一 提交于 2020-01-22 08:04:14
问题 Good day, I'm learning Spring MVC and I'm writting my tiny webapp following this tutorial but I slightly modified it as a "list of tasks" and not "list of users". One thing is not clear to me so I'd like to ask for an explanation. This is my edit.jsp: <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%> <html> <head> <title>Edit task<