Error creating bean with name ‘requestMappingHandlerAdapter’

Am creating a simple REST service using Springframework with Tomcat. The response should have to be in json like {“id”:”101″,”name”:”Ram”} .When ever I run, am getting the following error org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘requestMappingHandlerAdapter’ defined in class org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerAdapter()] threw exception; … Read more

Understanding Spring Boot @Autowired

I don’t understand how spring boot’s annotation @Autowired correctly works. Here is a simple example: @SpringBootApplication public class App { @Autowired public Starter starter; public static void main(String[] args) { SpringApplication.run(App.class, args); } public App() { System.out.println(“init App”); //starter.init(); } } — @Repository public class Starter { public Starter() {System.out.println(“init Starter”);} public void init() { … Read more

Spring: Different exception handler for RestController and Controller

In Spring you can set up “global” exception handler via @ControllerAdvice and @ExceptionHandler annotation. I’m trying to utilize this mechanism to have two global exception handlers: RestControllerExceptionHandler – which should return error responses as json for any controller annotated with @RestController ControllerExceptionHandler – which should print error message to the screen for any other controller … Read more

How can I read all users using keycloak and spring?

I’m using keycloak 3.4 and spring boot to develop a web app. I’m using the Active Directory as User Federation to retrieve all users information. But to use those information inside my web app I think I have to save them inside the “local-webapp” database. So after the users are logged, how can I save … Read more

Spring Boot JPA@CreatedDate @LastModifiedDate not being populated when saving the object

I am writing an app with Spring Boot + JPA, using a Postgres database. I have a User Entity and I am trying to get a timestamp when the user record is saved and/or modified. This is not working. The record that is being saved has “null” for both createdDate and lastModifiedDate. Here is all … Read more

Should validators in spring access the database?

I’m not really sure if it’s a good design decision to make the validators validate commands based on the state of the database. For example if I need to validate a User bean besides checking if the email and username are empty etc. I also need to reject values if they are already used. Should … Read more

spring mvc rest response json and xml

I have the requirement to return the result from the database either as a string in xml-structure or as json-structure. I’ve got a solution, but I don’t know, if this one is the best way to solve this. I have two methods here: @RequestMapping(value = “/content/json/{ids}”, method = RequestMethod.GET) public ResponseEntity<String> getContentByIdsAsJSON(@PathVariable(“ids”) String ids) { … Read more

Return a file from Controller in Spring

I am new to spring. I have a controller with a RequestMapping for several GET parameters. They return a String . But one method needs to return a file in the “/res/” folder. How do I do that? @RequestMapping(method = RequestMethod.GET,value = “/getfile”) public @ResponseBody String getReviewedFile(@RequestParam(“fileName”) String fileName) { return //the File Content or … Read more

getting package org.springframework.transaction.annotation does not exist error while packaging app

I am quite new in Spring world. I have developed a DAO using Spring 3.2 and Hibernate 4.1.9 but I have noticed a strange thing. All the used dependencies related to Spring belong to the 3.2.1 version, except that related to the spring-aop module. For this module I have to use the 3.2.0 version because … Read more

How to retrieve JNDI using Spring @Configuration instead of XML configuration

I’ve started development of a new Spring 3.2.4 application and am trying to use Java based configuration instead of XML files as I have used in the past. However, I am having trouble making the transition. Using XML, I would code it as follows: <!– application datasource –> <bean id=”dataSource.jndi” class=”org.springframework.jndi.JndiObjectFactoryBean” scope=”singleton” lazy-init=”true”> <property name=”jndiName” … Read more