Injection context in Spring MVC controller, similar to Jersey InjectableProvider

I have a custom InjectableProvider in a Jersey project that does some query / session work to invoke the user ID that my RESTful service needs. This means that I can write service methods, for example:

@GET
@Produces(MediaType.APPLICATION_JSON)
public String getByAccountIdAndGroup(@InjectAccount(required=false) String accountId, @DefaultValue("default") @QueryParam("productGroup") String productGroup) {
...
}

Where @InjectAccount is my custom annotation.

I would like to do a similar thing for SpringMVC controllers in the same project. That is, I want to write:

@RequestMapping(method = RequestMethod.GET)
public String showForm(Model model, @InjectAccountSpringMvc String accountId) {
...
}

I expect that you will have to consider common code, rather than using the Jersey injection tool directly.

, Spring - - bean, , , Spring MVC . , :

@Component
@Scope("THREAD")
public class AccountResolver {
   @Autowired
   private HttpServletRequest request

   private String theAccount=null;

   public String getAccount() {
      if ( theAccount == null ) {
         theAccount=resolveAccount();
      }
      return theAccount;
   }
}

.

/ !

Alfie.

+4
1

, Spring. HandlerMethodArgumentResolver.

supportsParameter . resolveArgument , .

+2

All Articles