spring - How do I setup a small maven project for Springframework development -
i created simple maven project eclipse(no archetype), , have wound empty skeleton. whenever create spring project, create template, , contains number of xml configurations , files. not great spring developer, , not know ll required set spring. necessary files , folders need started writing spring mvc web application, , content should put in them?
here application structure far:
if helpful, here pom.xml
:
<?xml version="1.0"?> <project xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <modelversion>4.0.0</modelversion> <groupid>org.reimaginenewton</groupid> <artifactid>site</artifactid> <version>1.0.0.0</version> <packaging>war</packaging> <name>re-imagine newton</name> <description>the site @ reimaginenewton.org</description> <dependencies> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>4.1.6.release</version> <scope>compile</scope> </dependency> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-mongodb</artifactid> <version>1.7.0.release</version> <scope>compile</scope> </dependency> <dependency> <groupid>org.springframework.mobile</groupid> <artifactid>spring-mobile-device</artifactid> <version>1.1.3.release</version> <scope>compile</scope> </dependency> <dependency> <groupid>org.springframework.social</groupid> <artifactid>spring-social-core</artifactid> <version>1.1.0.release</version> <scope>compile</scope> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-web</artifactid> <version>4.0.1.release</version> <scope>compile</scope> </dependency> <dependency> <groupid>org.springframework.social</groupid> <artifactid>spring-social-facebook</artifactid> <version>2.0.1.release</version> <scope>compile</scope> </dependency> <dependency> <groupid>org.springframework.social</groupid> <artifactid>spring-social-twitter</artifactid> <version>1.1.0.release</version> <scope>compile</scope> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>javax.servlet-api</artifactid> <version>3.1.0</version> <scope>compile</scope> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jsp-api</artifactid> <version>2.0</version> <scope>compile</scope> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <version>1.2</version> <scope>compile</scope> </dependency> </dependencies> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>central repository</name> <url>http://repo.maven.apache.org/maven2</url> </repository> </repositories> <pluginrepositories> <pluginrepository> <releases> <updatepolicy>never</updatepolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>central repository</name> <url>http://repo.maven.apache.org/maven2</url> </pluginrepository> </pluginrepositories> <build> <sourcedirectory>c:\users\james\documents\workspace-sts-3.6.4.release\site\src\main\java</sourcedirectory> <scriptsourcedirectory>c:\users\james\documents\workspace-sts-3.6.4.release\site\src\main\scripts</scriptsourcedirectory> <testsourcedirectory>c:\users\james\documents\workspace-sts-3.6.4.release\site\src\test\java</testsourcedirectory> <outputdirectory>c:\users\james\documents\workspace-sts-3.6.4.release\site\target\classes</outputdirectory> <testoutputdirectory>c:\users\james\documents\workspace-sts-3.6.4.release\site\target\test-classes</testoutputdirectory> <resources> <resource> <directory>c:\users\james\documents\workspace-sts-3.6.4.release\site\src\main\resources</directory> </resource> </resources> <testresources> <testresource> <directory>c:\users\james\documents\workspace-sts-3.6.4.release\site\src\test\resources</directory> </testresource> </testresources> <directory>c:\users\james\documents\workspace-sts-3.6.4.release\site\target</directory> <finalname>site-1.0.0.0</finalname> <pluginmanagement> <plugins> <plugin> <artifactid>maven-antrun-plugin</artifactid> <version>1.3</version> </plugin> <plugin> <artifactid>maven-assembly-plugin</artifactid> <version>2.2-beta-5</version> </plugin> <plugin> <artifactid>maven-dependency-plugin</artifactid> <version>2.8</version> </plugin> <plugin> <artifactid>maven-release-plugin</artifactid> <version>2.3.2</version> </plugin> </plugins> </pluginmanagement> <plugins> <plugin> <artifactid>maven-clean-plugin</artifactid> <version>2.5</version> <executions> <execution> <id>default-clean</id> <phase>clean</phase> <goals> <goal>clean</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactid>maven-resources-plugin</artifactid> <version>2.6</version> <executions> <execution> <id>default-testresources</id> <phase>process-test-resources</phase> <goals> <goal>testresources</goal> </goals> </execution> <execution> <id>default-resources</id> <phase>process-resources</phase> <goals> <goal>resources</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactid>maven-war-plugin</artifactid> <version>2.2</version> <executions> <execution> <id>default-war</id> <phase>package</phase> <goals> <goal>war</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactid>maven-compiler-plugin</artifactid> <version>2.5.1</version> <executions> <execution> <id>default-compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>default-testcompile</id> <phase>test-compile</phase> <goals> <goal>testcompile</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactid>maven-surefire-plugin</artifactid> <version>2.12.4</version> <executions> <execution> <id>default-test</id> <phase>test</phase> <goals> <goal>test</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactid>maven-install-plugin</artifactid> <version>2.4</version> <executions> <execution> <id>default-install</id> <phase>install</phase> <goals> <goal>install</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactid>maven-deploy-plugin</artifactid> <version>2.7</version> <executions> <execution> <id>default-deploy</id> <phase>deploy</phase> <goals> <goal>deploy</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactid>maven-site-plugin</artifactid> <version>3.3</version> <executions> <execution> <id>default-site</id> <phase>site</phase> <goals> <goal>site</goal> </goals> <configuration> <outputdirectory>c:\users\james\documents\workspace-sts-3.6.4.release\site\target\site</outputdirectory> <reportplugins> <reportplugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-project-info-reports-plugin</artifactid> </reportplugin> </reportplugins> </configuration> </execution> <execution> <id>default-deploy</id> <phase>site-deploy</phase> <goals> <goal>deploy</goal> </goals> <configuration> <outputdirectory>c:\users\james\documents\workspace-sts-3.6.4.release\site\target\site</outputdirectory> <reportplugins> <reportplugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-project-info-reports-plugin</artifactid> </reportplugin> </reportplugins> </configuration> </execution> </executions> <configuration> <outputdirectory>c:\users\james\documents\workspace-sts-3.6.4.release\site\target\site</outputdirectory> <reportplugins> <reportplugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-project-info-reports-plugin</artifactid> </reportplugin> </reportplugins> </configuration> </plugin> </plugins> </build> <reporting> <outputdirectory>c:\users\james\documents\workspace-sts-3.6.4.release\site\target\site</outputdirectory> </reporting> </project>
the necessary things code , spring application context.
the application config can setup using class annotated @configuration
described here. simple implemenation looks this:
@configuration @componentscan("org.example.springapp") public class springconfig { @bean public foo foo() { return new foo(); } }
and since have war file packaging need fire spring container in servlet engine.
public class webappinitializer implements webapplicationinitializer { public void onstartup(servletcontext container) throws servletexception { annotationconfigwebapplicationcontext rootcontext = new annotationconfigwebapplicationcontext(); rootcontext.register(springconfig.class); container.addlistener(new contextloaderlistener(rootcontext)); // register , map dispatcher servlet servletregistration.dynamic dispatcher = container.addservlet( "dispatcher", new dispatcherservlet(rootcontext)); dispatcher.setloadonstartup(1); dispatcher.addmapping("/"); } }
Comments
Post a Comment