views:

35

answers:

1

Hi,

I am wondering how others might have accomplished this. I found in the Spring documentation @required which I attempted to use in a 'test' but got this stmt INFO XmlConfigurationProvider:380 - Unable to verify action class [xxx] exists at initialization

I have found another way in spring to do this is to write custom init methods and declare those on the bean but it almost seems like this is a strange thing to do to a struts2 action.

In my application I inject through spring different web services (via setter injection) into different actions. I want to ensure on startup these are not null and set.

A: 

Use request or session spring scopes.

Then you can do the checks in a @PostConstruct method, what will you do there? Throw an exception? Well, something isn't set you will eventually get a NullPointerException.

Bozho
What I wanted to do was not allow the application to startup. After reading more about @required it does allow for null values so as a test I wrote an init method and used the spring assert functionality to say that a certain dependency was not null and if it is display an error message. You are right eventually I do get an NPE with prototype scope when the action is called but I would prefer to know there is an issue at startup. When I changed the scope to singleton(as a test) and used the init method I did get the desired behavior where the error was thrown and startup failed.
Barry