Spring: get the current user by injection

Currently I am getting the user with the usual SecurityContextHolder.getContext().getAuthentication().getPrincipal I wonder if it is possible to get it through the bean factory, like this @Service class UserProvider implements BeanFactoryAware { Bean

How to filter the domain-based request in spring-mvc

I have one war file for my application and I will be using 2 domains to access it. For example I want to access admin.jsp using admin.mydomain.com/adminpage and other jsp pages I want to access with local.mydomain.com. Also, admin.jsp should be only

Session Management in Angular JS, with Spring MVC

I am creating a project in AngularJs at frontend and Spring MVC in backend. Now assume when a used logged in and if he wants to update his information, for this i have created an api which request for emailid and update the rest object in database of

Spring MVC: complex object as a parameter

I started to learn spring boot and I'm faced with problems. I have following code: @RestController public class UserController { @RequestMapping("/") public String getMessageInfo(Message message) { return "Id is " + message.getId() + &

Can not sort null with comparator

This question already has an answer here: What is a NullPointerException, and how do I fix it? 12 answers I keep getting a nullpointerexception when I try to sort users where a certain user has a null value in his profile. I was under the impression

spring security / logout does not work cross-origin requests

My AngularJS application has a login and logout button. The login button works fine and also all other requests that are send to my backend. The problem occurs when I try to logout. I am getting following error. XMLHttpRequest cannot load http://loca

Error 401 when using HttpComponentsClientHttpRequestFactory

Am getting 401 Unauthorized error for few of the URLs when using HttpComponentsClientHttpRequestFactory, however it works fine when using Simpleclienthttprequestfactory. The reason why i want to use HttpComponentsClientHttpRequestFactory is for readi

Static files can not find Spring MVC + Thymeleaf

I have a spring application which is a starting project. I used Thymeleaf as template engine. But i have problem which is i can not reach to the static files such as CSS or javascript. This is my file structure for this application. This is the confi

How to pause @JmsListener in my spring startup app?

Here are my Hornetq configuration in spring boot. spring.hornetq.mode=embedded spring.hornetq.embedded.enabled=true spring.hornetq.embedded.persistent=true spring.hornetq.port=5445 spring.hornetq.embedded.queues=jms.testqueue Here is my Producer publ

Spring Batch to treat multiple items at once

We are using Spring Batch to do some processing, reading some ids via Reader and we want to process them as 'chunks' via a processor then write to multiple files. But the processor interface allows only one item to processed at a time, we need to do

Spring cacheable unsynchronized

I have a singleton class (@Service annotated). This class has a method which takes 200/300ms to execute. This method is annotated with @Cacheable and synchronized. @Cacheable(value="nextPlaying", key = "#startingFrom.getYear() + #startingFr

count the number of columns in mongoDB using Java

I have installed MongoDB in my system and I inserted 10 documents into the username collection. That document contains name, roll no, city fields. I need to count the number of fields in the username collection. I except 3... How to get the 3 from ja

Remote SourceSource

Has anyone had any luck constructing a PropertySource that uses a remote source (for example a database) from which to retrieve property values. The idea would be to construct a PropertySource (needs some connection information such as host/port) and

Spring data JPA Java Config HibernatePersistence.class

HibernatePersistence.class is deprecated. What should be the alternative for this code? import org.hibernate.ejb.HibernatePersistence @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean

Get the Pom application version

I have a rest endpoint used to return information about application (so far only app version) But so far this info is hardcoded, and it's pretty easy to forget to change it. I will be better to retrieve app version from pom or manifest file. Is there

Is there a way to get this session ID using only javascript?

I am developing a spring MVC based Java Application. When you open a browser window, a session id is created. on the server side we can get the session id, something as follows httpServletRequest.getSession().getId() Is there a way to get this sessio

Error 404 when using UrlBasedViewResolver and JstlView

I'm creating a simple hello world application using maven and java-based configuration. However, I keep on getting a 404 error on a simple href link. The files are below. index.jsp <%@ page language="java" contentType="text/html; charset

spring display transaction with log4j

i want to look the transaction activity in spring,such as TransactionInterceptor] - Getting transaction for x.y.service.FooService.insertFoo <!-- the transactional advice kicks in here... --> [DataSourceTransactionManager] - Creating new transaction

Call Spring Batch Jobs on the Remote Server

I use Spring Batch Admin to manage and monitor jobs and executions. How can I call a job and launch it from a standalone java application with given HTTP Connection to the server containing Spring Batch Admin WebAPP. Thank you for any helpYou can use

Edit JSon response for @ManyToOne using Jackson and Spring

I have two classes: public class Team { private Long id; private String name; ... } public class Event { private Long id; @ManyToOne private Team homeTeam; @ManyToOne private Team guestTeam; ... } Controller: public @ResponseBody List<Event> getAll(

Simple Spring MVC + Security Configuration

I am trying to set up a simple spring mvc / spring security webapp, but I can't seem to find the way to accomplish this: I'd like to use the normal @Secured annotations, and if the user isn't logged in I'd like them to be redirected to the login page

External CSS does not load in the Web page

I am developing a web application using Spring and Tomcat 7.0. When I test the page in a browser it does not apply the CSS because it is unable to load the external stylesheet. Here are my various files web.xml <?xml version="1.0" encoding=&q

Edit an object's properties with Spring Forms

I'm a bit confused about how an object could be edited with Spring Forms, for instance: suppose I have an object Person who has a lot of attributes because I obtain it from a dao, and I only want to provide the field "street" for editing, I woul