2 Replies Latest reply on Mar 1, 2013 11:40 AM by msduk

    Spring MVC Example

    msduk

      Hi I am struggling to get a Spring 3 MVC webapp working within a  Switchyard deployment scenario.

       

      I have a simple test case set up exposing a sample API service with a remote binding.

       

      How would I go about consuming this from a switchyard webapp project spring controller?

       

      From what I have read @Inject should work within spring using Weld CDI beans but it is not working for my remote @Service

       

      I have tested it with non Spring beans and it is available.

        • 1. Re: Spring MVC Example
          splatch

          Hey Mark,

          You may take a look on presentation from last year about integrating CDI with Spring. My thinking is that Spring bridges somehow CDI annotations into Spring context but it simply ignores custom extensions. In other words you may use CDI in very limited way.

          • 2. Re: Spring MVC Example
            msduk

            Hi thanks for the response. I had already read your presentation, very helpful.

             

            <cdi:bean-manager/>

            <cdi:bean-reference id="apiService" type="com.api.ApiService"/><!- remote ->

            <cdi:bean-reference id="webServiceBean" type="com.web.WebServiceBean"/><!-- local ->

             

            I found I was unable to wire any remote interface directly to the controller. However I can reference ApiService if it is injected into the local bean. Which seems odd to me.

             

            @Service(WebService.class)

            public class WebServiceBean implements WebService {

             

            @Inject @Reference

            ApiService apiService;

             

            public String apiServiceMessage() {

                 return apiService.demoApi("hi");

            }

             

             

            >>>

             

            @Controller

            public class HomeController {

             

              @Autowired <!-- works -->

                      WebServiceBean webServiceBean;

             

                      @Autowired <!-- doesn't work-->

                      ApiService apiService;

             

              <!-- works -->

              webServiceBean.apiServiceMessage()

             

            I am guessing, as dont know a huge amount about Spring behind the scenes and even less about CDI, but the remote interfaces dont seem to be exposed by the bridge.

             

            I dont know if anyone else has a better solution?