Over a million developers have joined DZone.
Platinum Partner

Debugging Spring Components with Namespace based configuration

· Performance Zone

The Performance Zone is brought to you in partnership with New Relic. New Relic APM provides constant monitoring of your apps so you don't have to.

Sometimes it hard to debug a Spring component especially if it is Namespace based standard spring components. In this blog I will explain how to debug a spring security component. Consider the below code:

<user-service id="userService">
<user name="${some-user}" password="${some-password}"
authorities="secure-access" />

In the above component if there is a problem with authorization, how do you know what value is being passed? How do you know which class is this and where to put the debug break point? If you notice “user-service” is just another bean with Spring id as “userService”. Namespace based configuration is a syntactic sugar for bean definition. Spring JUnit test and autowiring capability comes to your rescue. Define a simple test function as below:

private Object userService;
public void testUserService(){

Run the above test, it will show as green. The logger message will print InMemoryDaoImpl class. Once you know that this is the object you can modify the test as below and further debug:

private InMemoryDaoImpl userService;
public void testUserService(){
UserMap map = userService.getUserMap();
//Assuming that krishna is set as dynamic property for some-user
UserDetails user = map.getUser("krishna");

This is one way to debug it, but there might be few other ways. Please suggest me.

I hope this helped.

The Performance Zone is brought to you in partnership with New Relic. New Relic’s SaaS-based Application Performance Monitoring helps you build, deploy, and maintain great web software.


Published at DZone with permission of Krishna Prasad , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}