Announcement Announcement Module
Collapse
No announcement yet.
Annotations and Controller Naming Conventions in Spring 2.5 + Netbeans 6.7 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Annotations and Controller Naming Conventions in Spring 2.5 + Netbeans 6.7

    After about three weeks of wanting to kill my self (This was more common 12 years ago when I started programming, not now however), I am finally decided to ask for some help..

    I usually can't stand n00bs who read ZERO documentation or blogs and then ask ignorant questions, so I've waited a while to finally see if I can't get some answers...

    I am doing a massive rewrite of an old PHP site, HUGE site, and of all the Java frameworks, I really like Spring MVC's docs, community and seemingly flexible architecture.

    However, like many Java frameworks, their complexities making "rapid development" a completely worthless venture. Here in lies the problem...


    1) I want to use Annotations for Controllers and Actions

    2) I want to implement MultiActionController interface and group my actions by controller

    3) I would like URL's to look like this domain.com/controller/action

    4) I want the Controller and Action portion of the URL to be map to the correct controller and action automatically with no XML config

    5) I would like the URL to NOT be case sensitive which I believe is possible with Spring.. I remember seeing some classes and config for this some where. But this is not a deal breaker.

    6) I want to develop the app using NetBeans 6.7 starting with the default web app project using the Spring MVC framework selected for the framework.


    That's it.. That' all I am trying to accomplish.. In my project, I have failed for three weeks to even show a view.

    I have used RoR, CakePHP, ASP.net MVC, Joomla 1.5, and so many other MVC frameworks without any trouble. The concepts are universal... It's 100% ridiculous that a developer who's been coding for over 10 years cannot pick up a simple MVC framework, read the docs and create a site without having to loose sleep for three weeks lol.. I mean, seriously, am I the the only one here who thinks it's a bit silly that the default netbeans project using the Spring MVC framework doesn't use Annotations and only allows simple .htm file references to views? Not to mention doesn't even support Multiple actions per controller by default lol.. My goodness, it's like the default project was created for someone with a 3 page web app!

    ** OK ranting done **

    If any one would like to post their dispatcher-servlet.xml, web.xml and applicationContext.xml so I can see how to configure what I am looking to do I would appreciate it like none other :-)

    Thanks in advanced!
    Joshua

  • #2
    starting

    Hi

    Here is a tutoriel on the web for starting http://blog.netapsys.fr/index.php/po...n-A-Spring-MVC

    Regards

    Comment


    • #3
      I appreciate the tutorial however it meets just about none of my requirements lol...

      1) It's using .htm extension
      2) It's already more complex then it needs to be using Jetty and Mavin
      3) Is not netbeans lol (Why do people still use Eclipse again?)
      4) Controllers and annotations are not used nor does it show how to use the MultiActionController

      In the time it took to get just ONE response on this issue, I have already setup and configured a new app using Wicket 1.4.. Been able to read tutorials which CLEARLY showed me how to use the framework with it's ZERO config, ZERO xml setup..

      I have also setup my own set of controllers based on convention and in the last hour can do 100% more with Wicket then I could with Spring MVC.. Not to mention I've eliminated 40 layers of complexity and instead have just two layers... That's it lol..

      I doubt anyone is going to actually be able to show me what I am looking to do. I am sure it's possible, I've read through the Spring Source documentation, I can even tell you what base classes they use lol.. But no one can seem to get it working..

      That ladies and gentleman is a problem. I fear the Spring is merely pushing their training and books instead of writing REAL plugins and test projects that actually show the real day to day use of Spring specially for web 2.0 developers.

      I guess I can cross Spring MVC off of my list and continue with Wicket, which by the way is form apache foundation, so it's not going any where! :-)

      Comment


      • #4
        sample

        Hi

        You can have sample here : http://www.springbyexample.org/

        I believe you should not use MultiActionController but annotation with spring 3 or 2.5

        you can find some example in the web like here http://www.criticalphase.com/2009/06...5-annotations/

        Regards

        Comment


        • #5
          Annotations and Controller Naming Conventions in Spring 2.5 + Netbeans 6.7

          Hi Joshua,

          speaking for the NetBeans team, we are aware that the NetBeans support for Spring could be improved and enhanced, especially in the light of the upcoming Spring 3.0 release. We are eager to hear input from real users such as yourself, and we would like to know what specific improvements you would like to see, so we can focus on them in the next release. Feel free to either file enhancement/feature requests in the NetBeans issue tracker: http://www.netbeans.org/issues/enter_bug.cgi, or drop me an e-mail at petr.jiricka at sun dot com. Thanks,

          Petr

          Comment


          • #6
            I appreciate the posts, links, etc.

            Please understand I am not trying to be a complete @$$ here... lol Sometimes things come across differently online then vocally, but while these examples show usage of annotations, or some might show how to create a basic app.. They are far what what I am looking for.

            I can created a new project and setup a new controller for every action and have that working with a simple .htm extension in no time...

            Unfortunately, I do not want an app like this haha..

            If someone where to create a netbeans project, which means the following, I would be happy, impressed and belated!

            1) Support for extension-less URLS (domain.com/controller/action)
            2) Controllers would allow behavior as if inheriting from MultiActionController
            3) I want to use each controller to use several actions
            4) I want URL binding to be done using annotations
            5) I want controllers defined using annotations and not XML, heck, even using the Url Controller name binding functionality would make me happy.

            I have tried this for many many weeks now and cannot get it to work.. I can follow every single tutorial on the web for doing "A", or for doing "B" but when I combine it to make "C" it's always a no-go.. SOMETHING isn't playing right and I am not even getting an exception haha... Heck, I think Spring is finding the controller and action but it's still a no go for some reason.

            Matter of fact, the ONLY errors I am getting in the application are 404 errors, not one exception!

            Thanks, if anyone can come up with such a configured project, which shouldn't be that hard to ask for from a framework which boasts such a following I would be eternally grateful, and might even be will to throw some cash your way!

            Comment


            • #7
              Making Progress!

              Well I sat down today, and basically spent... THE ENTIRE DAY working from scratch on a new Spring 2.5 MVC app trying to replicate my requirements and making them work one by one..

              Here I will place my configs and Controller setup so that people can do the same thing, but there is still ONE LAST THING... Just one small detail...

              1 Problem left to solve:
              The only way I could get pretty urls (domain.com/controller/action/blah/blah)
              was too add a prefix in the servlet-mapping -> url-patter node inside of web.xml.

              For instance, this is what I have for my web.xml...

              Code:
              <?xml version="1.0" encoding="UTF-8"?>
              <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                  <context-param>
                      <param-name>contextConfigLocation</param-name>
                      <param-value>/WEB-INF/applicationContext.xml</param-value>
                  </context-param>
                  <listener>
                      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                  </listener>
                  <servlet>
                      <servlet-name>dispatcher</servlet-name>
                      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                      <load-on-startup>2</load-on-startup>
                  </servlet>
                  <servlet-mapping>
                      <servlet-name>dispatcher</servlet-name>
                      <url-pattern>/app/*</url-pattern>
                  </servlet-mapping>
                  <session-config>
                      <session-timeout>
                          30
                      </session-timeout>
                  </session-config>
                  <welcome-file-list>
                      <welcome-file>redirect.jsp</welcome-file>
                      </welcome-file-list>
                  </web-app>

              As you can see, I have placed "/app/*" as the url-pattern. Now don't get to exited yet... Many of you are already thinking just remove the /app prefix and use /* and poof... NO SUCH LUCK my friends.. This is not struts2 nor Wicket... lol...

              Now that you're all aware of the last and final piece of the puzzle let me present the configs and controller setup I am using...


              applicationContext.xml
              Code:
              <?xml version="1.0" encoding="UTF-8"?>
              <beans xmlns="http://www.springframework.org/schema/beans"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xmlns:p="http://www.springframework.org/schema/p"
                     xmlns:aop="http://www.springframework.org/schema/aop"
                     xmlns:tx="http://www.springframework.org/schema/tx"
                     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
                  
                  <!--bean id="propertyConfigurer"
                        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
                        p:location="/WEB-INF/jdbc.properties" />
                  
                  <bean id="dataSource"
                        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
                        p:driverClassName="${jdbc.driverClassName}"
                        p:url="${jdbc.url}"
                        p:username="${jdbc.username}"
                        p:password="${jdbc.password}" /-->
                  
                  <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
                  
              </beans>
              dispatcher-servlet.xml
              Code:
              <?xml version="1.0" encoding="UTF-8"?>
              <beans xmlns="http://www.springframework.org/schema/beans"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xmlns:p="http://www.springframework.org/schema/p"
                     xmlns:aop="http://www.springframework.org/schema/aop"
                     xmlns:tx="http://www.springframework.org/schema/tx"
                     xmlns:context="http://www.springframework.org/schema/context"
                     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
                     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
                      
                  <context:component-scan base-package="com.test.controllers" />
              
                  <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
              
                  <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
              
                  <bean id="viewResolver"
                        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
                        p:prefix="/WEB-INF/jsp/"
                        p:suffix=".jsp" />
                  
              </beans>
              and the Web.xml you can view above

              Here is what I am using for a controller in package "com.test.controllers"

              com.test.controllers
              -> TestController.java

              Code:
              package com.test.controllers;
              
              import javax.servlet.http.HttpServletRequest;
              import javax.servlet.http.HttpServletResponse;
              import org.springframework.stereotype.Controller;
              import org.springframework.web.bind.annotation.RequestMapping;
              import org.springframework.web.servlet.ModelAndView;
              /**
               *
               * @author jholmes
               */
              @Controller
              public class TestController {
              
                  @RequestMapping("/test/index")
                  public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
                      return new ModelAndView("test", "model", "Model Here and I aint going away!");
                  }
              
                  @RequestMapping("/test/profile")
                  public ModelAndView profile(HttpServletRequest request, HttpServletResponse response) {
              
              
              
                      ModelAndView mav = new ModelAndView();
                      mav.addObject("message", "You Don't even know... BLAH BLAH BLAH");
                      mav.setViewName("profile");
              
                      return mav;
                  }
              
                  @RequestMapping("/test/update")
                  public ModelAndView update(HttpServletRequest request, HttpServletResponse response) {
                      ModelAndView mav = new ModelAndView();
                      mav.addObject("message", "You Don't even know... BLAH BLAH BLAH");
                      mav.setViewName("update");
              
                      return mav;
                  }
              
              }

              I have attached a screen shot of my netbeans project.. any other help?

              Comment

              Working...
              X