Questions tagged [spring-mvc]

19186 questions
1

votes
2

answer
3k

Views

Spring Boot, static resources and mime type configuration

I'm facing a Spring Boot configuration issue I can't deal with... I'm trying to build an HelloWorld example for HbbTV with Spring Boot, so I need to serve my 'index.html' page with mime-type='application/vnd.hbbtv.xhtml+xml' my index.html will be accessed as a static page, for instance http://myserv...
Cheloute
0

votes
0

answer
13

Views

Hibernate Could not fetch the SequenceInformation from the database but still works fine

I have 2 entities User And UserRole. if I make UserRole entities like this with a role as id everything works fine but this is bad because I can't have 2 different users with the same role: @Entity @Table(name = 'USER_ROLES', uniqueConstraints = @UniqueConstraint( columnNames = { 'ROLE', 'USERNAME'...
Patches Joe
1

votes
0

answer
13

Views

Spring Boot 2 - Session Issues

My security config reads like this: protected void configure(HttpSecurity http) throws Exception { http .antMatcher('/**') .authorizeRequests() .antMatchers('/*.js', '/*.ico', '/*.png', '/*.css').permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage('/login') .loginProcessingUrl('...
Magd Kudama
1

votes
1

answer
873

Views

Visual Studio Code - Java - Lombok - The method is undefined for the type

I downloaded the following project and imported it into Visual Studio Code: https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example I have a problem on the following class, when invoking: car.getName(). https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example/blob/d5c95916...
davidesp
1

votes
2

answer
42

Views

Should multiple Spring controllers direct to same view file?

Suppose in Controller A, I have @GetMapping('/path/1') public String getIndex() { //it's own unique logic ... return 'path/to/file'; } and in Controller B, I have @GetMapping('/path/2') public String getIndex() { //It's own unique logic ... return 'path/to/file'; } Is it a good practice to have two...
John Doe
1

votes
5

answer
714

Views

How to get current user in every request in Spring Boot?

I would like to get the username of the user in every request to add them to log file. This is my solution: First, I created a LoggedUser with a static property: public class LoggedUser { private static final ThreadLocal userHolder = new ThreadLocal(); public static void logIn(String user) { userHo...
TranNgocKhoa
1

votes
2

answer
62

Views

Asynchronous AJAX return after page loads

I'm using Spring MVC and I need to make an asynchronous call to the server only once when the JSP page has loaded completely. What I actually have is a Controller that returns a List. I call the Controller using AJAX. The problem with my solution is that I'm not able to get the data of List after lo...
1

votes
1

answer
51

Views

Spring MVC - Rest API where is the best place for put entity together

Where is the best place for setting parent entity? In the other word, where is the best place to put entity together? In the controller, finding parent entity and setting to child then saving? @RestController public class SomeController{ @Autowired private SomeService someService; @PostMapping('/par...
mnesimi
1

votes
3

answer
39

Views

DateTimeFormat annotation in spring time zone issue

I am having an issue to convert string to date object. While converting it is picking the GMT timezone and getting changed into previous date. I want to ignore the timezone.If the string value is '03/12/2019' then it should the same date irrespective of the timezone. @DateTimeFormat(pattern = 'MM/d...
sree
1

votes
2

answer
4.5k

Views

Is request.getMethod().equalsIgnoreCase(“post”) a bad idea in a (pre-Spring-3.0) Spring blog app?

In Spring 3.0 annotations allow you to specify the blog post method as a url. But prior to that version of Spring, is this the best way to achieve it: @SuppressWarnings('unchecked') public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse arg1) throws Exception { ModelAndVie...
apfel
1

votes
5

answer
1.4k

Views

Top use cases for using Sessions in Java web application

I've been always trying to avoid using Sessions. I've used spring security or other ways of having user logged in the application, which is I suppose the major use case for using Sessions. But what are the other use cases ? Could you please make a list of those most important ones ? How come that I...
lisak
0

votes
1

answer
17

Views

What will be default scope while we use @inject

Since when comparing with spring the default scope is singleton. is that the same in javax inject?? If we need to change the scope how can we achieve??? class A{ @inject B b public void method1(){ ..... b.invoke(); ... } } class B{ public void invoke(){ ...... } }
Abilash Cv
0

votes
0

answer
4

Views

Error creating bean with name 'accountController': Unsatisfied dependency expressed through field 'Service_functions'

Trying to connect to aws DynamoDB but currently running into the error shown in the title. What am i going wrong? I've looked at other solutions online to which i did not find an answer that worked for me. Full Error - org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating...
stackoverflown
0

votes
0

answer
18

Views

How to check if an Integer variable of @RequestParam type in Spring is “empty”?

If I have a code in which: @RequestParam(value = 'amount', required = false) Integer amount is one of my parameters, what can I do to prevent the user from assigning an 'empty' value to this parameter? For example: let's suppose they requested, on Postman, the URL http://localhost:8080/myproject?amo...
LP0956
1

votes
1

answer
71

Views

Thymeleaf: Only variable expressions returning numbers or booleans are allowed in this context

I have a SpringBoot 2.1.4.RELEASE RESTful Web Service app., using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file. I have this piece of code in one of my templates, ... But I got this error when rendering the template: org.thymeleaf.exceptions.T...
carles xuriguera
0

votes
0

answer
2

Views

How Spring Transaction behaves differently in different layer(service/repository layer)

Hi I need the following clarification on spring transaction. Seen is like: Service1.java @Service @Repository public class Service1 { @Autowired EmployeeRepo employeeRepo; @Autowired Repo repo; @Transactional public void m() { employeeRepo.save(new Employee(5, 'N3', 33, 3000)); repo.m1(); //M1 //m1...
Joe
0

votes
0

answer
20

Views

html text to pdf (Arabic and English characters)

I am trying to generate a pdf letter from html rich text contains Arabic and English characters, i create the document using itext, then add a footer and header to the document, now when i added the rich text using HTMLWorker, the Arabic letters did not rendered. I tried to use a custom font (arial...
Hazem Shoushari
1

votes
3

answer
106

Views

SQL Error: 23503, SQLState: 23503 in SpringBoot 2.1.4.RELEASE app

I have a SpringBoot 2.1.4.RELEASE RESTful Web Service app., using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file. I have this class: @Entity @Table(name='t_menu_alert_notification') public class MenuAlertNotification implements Serializable { /*...
carles xuriguera
0

votes
0

answer
32

Views

Spring boot MVC: RequestMapping isn't recognized in Spring boot 2.1.4

Can someone answer this silly question - How to configure Thymeleaf in Spring boot release 2.1.4? I have declared the right dependencies: org.springframework.boot spring-boot-starter-parent 2.1.4.RELEASE org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-th...
AppleBuckler
1

votes
2

answer
757

Views

How to increase OAuth access token expire time in Jhipster app?

Tried to increase the value of tokenValidityInSeconds = 1800; to some value say 3200 in JHipsterProperties.java file but does not reflect in the token expiry time.
Raj
1

votes
1

answer
11.8k

Views

415 Unsupported Media Type (org.springframework.web.client.HttpClientErrorException)

I am new to WebServices. I am working on an application where I am using AnhularJs1.x at client side which sends data to Spring Rest Controller. The architecture of the application is micro-services based. I am able to receive the data from angular to Front end Rest Controller which are in the same...
AkashSharma
1

votes
1

answer
525

Views

Spring MockMvc redirect not working

I am trying to mock a post request using the below code . I am testing a spring security login request. MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).addFilter(springSecurityFilterChain) .apply(springSecurity()) .build(); MvcResult mvcResult = mvc.perform(post('/j_spring_security_check...
lives
1

votes
2

answer
998

Views

Spring-MVC : How to stream mp3 file from controller

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...
We are Borg
1

votes
3

answer
83

Views

Java Spring : Upload multiple MultipartFile files along with JSON as a body into single request(HTTP->POST)?

Hello Friends, I am looking for a solution where I can upload multiple MultipartFile along with input JSON body. I knew there are many related things available but none of the thing were I find my solution. which provoke me to ask a question to community. My requirement is something likewise, I hav...
vishal gajera
1

votes
3

answer
7.1k

Views

Spring validations default messages

I need to get the resolved error messages programmatically in the controller. The default validation message for typeMismatch errors are not populating from my messages.properties file. I have a form backing object where a field is an Integer. If I submit a string for that field I get: Failed to...
Jeremy
1

votes
1

answer
264

Views

Not able access multiple data sources in Spring boot

I am new to Spring & Spring boot and I am trying to access two data sources but am I able to connect to only one data source. when I try to call a function accessing 2nd data source the call goes to the first data source and I get the below error, com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExce...
Arigato Manga
1

votes
1

answer
34

Views

video is not fetching completly,

I want to fetch video from mongodb than it should play that video up to video size, but its playing only some second, i gave maxUploadSize is 20mb and maxInMemorySize also 20mb,but on the jsp page, its fetching only 1mb video even video size more than 1mb. I am not getting what to do, video should p...
Laxmi Prajapati
1

votes
3

answer
372

Views

Spring @Transactional annotation making my class not able to Autowire

I have a class SaveRoute which has got an auto-wired property SaveProcessor. This SaveProcessor class has got a method which is annotated with @Transactional annotation. When I try to run my application, Java is throwing an exception that bean SaveProcessor dependency injection failed. When I remov...
Jewel Jose
1

votes
2

answer
100

Views

Error 404 on SpringMVC using Maven

I keep getting this Error 404 and I've done/looked at almost all the solutions on StackOverflow that are relevant and still haven't fixed my problem. Why am I having this error? When I do http://localhost:8080 it gives me my index.jsp page, but when I do http://localhost:8080/index.jsp of http://loc...
reagan yuan
1

votes
0

answer
77

Views

Spring @WebFilter causes 404 on prod, runs fine on local

I am using a @WebFilter with urlMapping = '/*' option. (Also tried with servlet). I use it to manage my oAuth single sign ons. It runs fine on local with tomcat on eclipse. On prod it throws a 404. Disabling the filter(thus, by passing the filter) works fine. Any pointers anyone? AppConfig.java: @...
dixyantar panda
1

votes
0

answer
71

Views

for loop not working in JavaScript while Second Attempt

I got stuck in a very strange problem need help. Actually i am trying to assign some value to dynamically generated input fields. So i tried the following code snippet. I mean to say in first step i only need to assign value for first 10 IDs and then again if assigning some other values to rest of I...
Created Bylucky
1

votes
1

answer
88

Views

MockMvc - calling a query with a complicated object

I want to send to the controller a complex object consisting of files and simple types. public class ContributionNew { private List elementsToAdd; private Map elementsToUpdate; private Set idsToDelete; private Set sources; private String comment; } public class Photo extends MovieInfoDTO { private M...
sfsdfgdsg
1

votes
0

answer
388

Views

How handle correctly HTTP Accept header when is either empty or null?

I am working with Spring Framework about Rest. I have the scenario about testing when the request is a GET and Accept is either empty or null. It is closely related with: @GetMapping is called even when Accept is defined how null I have read the following: How to interpret empty HTTP Accept header?...
Manuel Jordan
1

votes
0

answer
563

Views

Unique records on multiple columns in Spring Boot

I have for example 2 tables: Table 1: user userid titleid (Links to title table below) name surname Table 2: title titleid title User Entity class: @Entity @Table(name='user', uniqueConstraints={@UniqueConstraint(name='user_unique', columnNames={'titleid', 'name'})}) @NamedQuery(name='User.findAll'...
Quentinb
1

votes
1

answer
586

Views

spring.config.location not working without classpath resource

I have my config class as below @Configuration @PropertySource(value= 'classpath:conf/agent.properties') public class AppConfig{ While running the application using java -jar app.jar spring.config.location=path-to-external-property-file the application runs fine and takes the properties from the ex...
java_dev
1

votes
1

answer
240

Views

Spring REST equivalent of ContainerRequestContext

What is a Spring equivalent of Jersey's ContainerRequestContext? I am trying to get the SecurityContext (.getSecurityContext()) like we can from a ContainerRequestContext. Does spring-mvc have something similar?
user9176614
1

votes
0

answer
138

Views

How to send array of json objects to spring controller using ajax

I have converted all tables into json format using the below code: var table2 = $('#yTable').tableToJSON(); alert(JSON.stringify(table2)); How do I send these three json arrays to spring controller? In spring controller I want these json array of objects as separate params: [ {'Label':'A',...
mantelinga r
1

votes
1

answer
41

Views

Show only thumbnail of video on jsp page

I am trying to show only thumbnail of a video on jsp page without downloading video. Can anyone tell me is this possible or not? Or if possible what is solution for that?
1

votes
0

answer
84

Views

Spring default error handler tries to write error html to output stream used by spring to return file content

Hi I have the following problem I have a Controller that is used to download a file public ResponseEntity downloadFile(String path) { FileContentInformation fileContent = getInputContentFromSomewhere(); //Content-Type, Content-Length, Content-Disposition, etc. final HttpHeaders responseHeaders = cr...
maczikasz
1

votes
0

answer
106

Views

spring.application.json is not working on windows os

I am setting system property spring.application.json={'foo': 'bar'} in my spring boot application. This works well in all linux OS but not in windows. Is there something specific to windows? When I run my spring boot, in linux I see INFO eEncryptablePropertySourcesPostProcessor : Converting Propert...
sureshbabu

View additional questions