Category Archives: Spring

Spring Security – Access is denied (user is not anonymous) spring-security-core-4.0.3.RELEASE

Questions: can anyone see an failure in this Spring Security Config File? After Login the i get a debug message: Access is denied (user is not anonymous); delegating to AccessDeniedHandler org.springframework.security.access.AccessDeniedException: Access is denied but I can access the application. @Override protected void configure(HttpSecurity http) throws Exception { http. authorizeRequests().antMatchers(“/register/verification/*/*”).anonymous() .and().authorizeRequests().antMatchers(“/register/test”).anonymous() .and().authorizeRequests().antMatchers(“/register”).anonymous() .and().authorizeRequests().antMatchers(“/forgot_password”).anonymous().and().authorizeRequests().antMatchers(“/triggeredBy/password**”).permitAll() .and().authorizeRequests().antMatchers(“/err/403”).permitAll() .and().authorizeRequests().antMatchers(“/login”).anonymous()… Read More »

Autowiring Map not working as expected

Questions: I’m using Spring 3.0.4. I have some beans that use the @Autowired annotation on Maps. These maps are defined within an application-context.xml file (as these maps are constructed using several factory methods). When I use my debugger, I can see the map gets constructed using the properly (expected) bean id. However, once the autowiring… Read More »

What's the simplest way to change from exception logging to exception handling in a Spring MVC app?

Questions: My Spring MVC app is full of methods that look like this: @RequestMapping(value = “/foo”, method = RequestMethod.GET) public final void foo(HttpServletRequest request, ModelMap modelMap){ try{ this.fooService.foo(); } catch (Exception e){ log.warn(e.getMessage(), e); } } Exceptions are caught and logged but not handled otherwise. The fooService called above does the same thing, never throwing… Read More »

Spring Integration: Content based router with default output channel?

Questions: I’d like use Spring Integration to implement a content based router that uses a default output channel if the expression value doesn’t match any of the mappings. Here’s my bean definition: <int:router input-channel=”channel_in” default-output-channel=”channel_default” expression=”payload.name”> <int:mapping value=”foo” channel=”channel_one” /> <int:mapping value=”bar” channel=”channel_two” /> However, it seems the default output channel is never used. If… Read More »

java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource

Questions: Iam doing a project on spring MVC with maven.Iam getting an error java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource while running project.I include all the dependencies i think..below my codes.waiting for your reply WEB.xml <?xml version=”1.0″ encoding=”UTF-8″?> <web-app xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”http://java.sun.com/xml/ns/javaee” xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd” version=”3.0″> <servlet> <servlet-name>AccPerSpring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AccPerSpring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> servlet-context.xml <?xml… Read More »

Find method level custom annotation in a Spring context

Questions: All I wanted to find out was “all the class/methods in Spring beans which are annotated as @Versioned”. I created my custom annotation as, @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Versioned { ….. } This annotation works perfectly when I use Java reflection to find methods as: for(Method m: obj.getClass().getMethods()){ if(m.isAnnotationPresent(Versioned.class)){ …. // Do… Read More »

How to force Spring HATEOAS resources to render an empty embedded array?

Questions: I have the following controller method: @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = “session/{id}/exercises”) public ResponseEntity<Resources<Exercise>> exercises(@PathVariable(“id”) Long id) { Optional<Session> opt = sessionRepository.findWithExercises(id); Set<Exercise> exercises = Sets.newLinkedHashSet(); if (opt.isPresent()) { exercises.addAll(opt.get().getExercises()); } Link link = entityLinks.linkFor(Session.class) .slash(id) .slash(Constants.Rels.EXERCISES) .withSelfRel(); return ResponseEntity.ok(new Resources<>(exercises, link)); } So basically I am trying to get the expose a Set<>… Read More »

Spring cache abstraction – distributed environment

Questions: I would like to use the spring cache abstraction in my distributed web application. My web application is consists of a web application that runs on 3 different tomcats with load balancer. Now, My problem is how exactly can I @Evict cache in all tomcats when another tomcat preforms an update? Does spring supports… Read More »