1

Can some one give me a link for multiple dispatcher servlet example?. I am trying to run two applications in a single Spring MVC. I have checked different examples in google and written everything in web.xml, wrote two *-servlet.xml files. I have different jsp pages. Specified different url's for the application. But still one of the application is not running?

Any brief example link or can anyone atleast tell me the configuration files required when writing two dispatcher servlets in a Spring MVC.

Thank You Sam

  • This link might help you, follow Chin Huang's answer http://stackoverflow.com/questions/4054896/how-does-dispatcherservlet-work-if-we-have-multiple-xml-configuration-file – Chand Oct 19 '12 at 17:40
  • I have already seen that link. Thank You Chand. I have two *-servlet.xml files. I also included two dispatcher servlet mappings in my web.xml. But when I try to go to an application, it says that the resource is not found. – Sandeep Govind Oct 19 '12 at 18:12
  • One more point, do I need to write two *-spring.xml files to map the beans to it's classes. I think that I am going wrong in this *-spring.xml file. – Sandeep Govind Oct 19 '12 at 18:14

2 Answers2

0

It’s up to you whether u need to maintain 2 separate spring config files or not. You can keep just one spring config xml but it’s good to have separate config files for the sake of 'Modularity. Again im not quite sure what you meant by 2 application here.

Chand
  • 91
  • 4
  • can you share the stack trace?, it'll help us to see what's wrong here – Chand Oct 19 '12 at 18:32
  • Hi chand..thanks for your answer...I mean that I have two projects deployed in a single war files. Each project has a different jsp files, controllers and services classes. I am running this application in glassfish. Each project has a different url mapped Project 1: http://localhost:9090/project1/login Project 2: http://localhost:9090/project2/login My first project is shown corrrectly. But when I type the second project url, it shows nothing. I have two servlet mappings in the web.xml file and everything possible. If you need someother information, please ask me? – Sandeep Govind Oct 19 '12 at 18:35
  • Where can I find the stack strace? – Sandeep Govind Oct 19 '12 at 18:37
  • I don’t think that you can have 2 projects in single war file. What you need to do is you will have one project (Project1, single war) and you can have 2 different mapping extensions (localhost:9090/project1/login.app1, localhost:9090/project1/login.app2) for each modules. Ie. Module one, each request ends with .app1, and all the requests for module 2 will end with .app2 (A request in Module1 wd be, localhost:9090/project1/listCustomer.app1, whereas a request in Module2 will be localhost:9090/project1/getPrice.app2) – Chand Oct 19 '12 at 18:58
  • And then your web xml will be as app1 /app1/* app2 /app2/* – Chand Oct 19 '12 at 18:59
  • I am sorry if I have confused you, by project I meant to say two modules in a single war file. And as you have told to have different extensions to each module, I used module 1 - .jsp and module2-.html. And my web.xml has the servlet mappings as you mentioned. But I still get HTTp Status 404 - the requested resource not found error. A small note: I use http://localhost:9090/project1/listCustomer.app1 and http://localhost:9090/project2/getprice2.app2 where 'project1' and project2' are my two modules. Is this OK? Thank You Chand again – Sandeep Govind Oct 19 '12 at 20:26
  • project1 and project2 are the web roots. So localhost:9090/project1/ and localhost:9090/project2/ are requests for 2 different web apps. So if localhost:9090/project1/listCustomer.app1 is working for you, use project1 in your second request url, ie. localhost:9090/project1/getprice2.app2 – Chand Oct 19 '12 at 20:53
  • Ok I will try that..but is it not possible to have project1 and project2 as seperate modules, becoz I would be showing these two as seperate modules to everyone...ANd as I have two dispatcher servlets defined, shouldn't it take in that form\ – Sandeep Govind Oct 19 '12 at 21:00
  • Yes you can, for that you have to configure the app server. In Tomcat we can do this – Chand Oct 19 '12 at 21:10
  • do I need to give some value to source argument? – Sandeep Govind Oct 19 '12 at 21:27
0

your url pattern should be:

<url-pattern>/project1/*</url-pattern> and <url-pattern>/project2/*</url-pattern>
Robert
  • 5,278
  • 43
  • 65
  • 115