Search code examples
javatomcatmavensts-springsourcetoolsuite

How to develop Tomcat applications with SpringSource Tool Suit?


I want objects of my Tomcat web application to be controlled by Maven's pom and Spring's IoC, including session scoped beans. My application consists of several objects which are accessed from jsp files.

What is the best way to design such an application with suit tools? Should I use Spring MVC Project template though I don't want to implement MVC tiers? Or there is another template somewhere on the Net?


Solution

  • The way I do using STS is like this. Go to

    File --> New --> Project --> Maven Project--> Create a simple project (skip archtype)  --> Enter the Artifact details. 
    

    For Example: Group Id: com.examples Artifact Id: MyProject

    Click on Finish.

    Now Right Click the project in Project Explorer and the Select Spring Tools--> Add Spring Project Nature.

    I usually use simple project because I like using the same pom.xml across projects and add/remove dependencies when needed.

    Sample pom.xml to get going with Spring

    <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>3.1.0.RELEASE</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>3.1.0.RELEASE</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.1.0.RELEASE</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>3.1.0.RELEASE</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.1.0.RELEASE</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.1.0.RELEASE</version>
         <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.1.0.RELEASE</version>
        <scope>runtime</scope>
      </dependency>
      <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <version>2.2.4</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.2.1</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
      </dependency>
    </dependencies>