Announcement Announcement Module
Collapse
No announcement yet.
Servlet and URL Mapping doubts - HTTP 404 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Thank you

    Dear Enrico.

    As I said in the beginning, I am quite new to Spring, but I am not new to programming and also I don't think I am that far from getting it working. So you don't need to go on forever, really.

    I am not asking lightly, I have read enough and I try to understand things instead of just hitting ctrl+c, ctrl+v... What I am doing, as you said, is a complex thing and that's why I am asking here. If it was easy I'd probably manage myself.

    Thank you anyway for taking the time of answering.

    Comment


    • #17
      I think this answers my doubts about component-scanning:
      http://forum.springsource.org/member.php?u=45487

      I have advanced quite a lot, I have succesfully configured a test project and now @Controllers get scanned and they respond to the URL specified in @RequestMapping("/whatever").

      However there are still a few things I don't get. As Enrico said, I probably should investigate a bit more about "the concept of separation between core Spring config loaded with listener and Spring web mvc config loaded with DispatcherServlet context-param", which may be preventing my target project from serve both the original Web Services and the mapped-to-@Controller URL's.

      Thank you,

      Luis
      Last edited by Moonwalker; Aug 20th, 2010, 02:34 AM.

      Comment


      • #18
        It is quite simple actually. When using Spring in a web application, you will have one CORE context containing everything non servlet-related (everything that is not web related: services, daos, pojos, aspects etc). This context is loaded by adding the following in web.xml:

        Code:
          <listener>
        	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          </listener>
          
          <context-param>
        	<param-name>contextConfigLocation</param-name>
        	<param-value>/WEB-INF/core-context.xml</param-value>
          </context-param>
        Then, you will have one more context for each Spring servlet you load in web.xml, for example if you use DispatcherServlet (Spring's web mvc):

        Code:
          <servlet>
        	<servlet-name>dispatcher</servlet-name>
        	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        	<init-param>
        	  <param-name>contextConfigLocation</param-name>
        	  <param-value>WEB-INF/dispatcher-context.xml</param-value>
        	</init-param>
        	<load-on-startup>1</load-on-startup>
          </servlet>
        
          <servlet-mapping>
        	<servlet-name>dispatcher</servlet-name>
        	<url-pattern>*.htm</url-pattern>
          </servlet-mapping>
        You will need one more context since you are also using Spring's web services.

        What about relations between those context? Well the core context will be at the disposal of every other servlet-loaded context. This means, for example, that you can inject and use core beans like services and daos inside your controllers.
        On the other hand, the reverse is not true: you can't inject beans from your web mvc context inside your core context, but why should you do something like that really? It's controllers that call services and not vice-versa!
        Also, your servlet context won't interact with each other, so, for example, you can't inject a controller inside a web service or vice-versa (again, why would you ever need to do something like that?)

        Hope I was clear enough...

        Comment


        • #19
          Interesting

          Thank you Enrico, what you said sounds good to me. But maybe I could do it better by serving my Web Services using Spring MVC annotations, couldn't I?

          Our services are SOAP based -not REST-, so I don't know yet if it's supported.

          Spring 3.0 REST services are explained quite well here:
          http://www.oudmaijer.com/blog/2010/0...th-spring-mvc/

          (not my goal but maybe someone was after it).

          Cheers,

          Comment


          • #20
            ...and SOAP Spring Web Services, here:

            v1.5: http://static.springsource.org/sprin...ml/server.html
            v2.0: http://static.springsource.org/sprin...ml/server.html

            Comment


            • #21
              Of course you can configure mvc in your web services context, that is perfectly fine. Just be aware that configuration you do in your dispatcherservlet context won't be available in the other one (they are two different contexts after all) so you must put scanning directives in both config files for example. What won't work is just direct injection between beans of different servlet contexts, because they are independent from one another, but that don't mean you can't configure them both as you like (althought the motivation behind usage of web mvc specific annotations in web services seems to slip my grasp, maybe I need to read something about Spring web services to get a clearer idea).

              Say hi to beautiful Barcelona for me.

              Comment

              Working...
              X