Springmvc+mongodb+maven Project Building Configuration

Source: Internet
Author: User
Tags set set log4j

Operation Steps I'm not refining anymore.

Project can run, tested, first on the configuration, another article on the code, to the source package please leave the mailbox

Project structure


Pom.xml

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" ><modelversion >4.0.0</modelversion><groupid>test</groupid><artifactid>springmvc_mongodb</ Artifactid><packaging>war</packaging><version>0.0.1-snapshot</version><name> Springmvc_mongodb Maven webapp</name><url>http://maven.apache.org</url><properties>< spring.version>3.2.3.release</spring.version><slf4j.version>1.7.2</slf4j.version>< log4j.version>1.2.16</log4j.version><junit.version>4.11</junit.version>< Jsonlib.version>2.4</jsonlib.version><shiro.version>1.2.2</shiro.version></properties ><dependencies><dependency><groupId>org.springframework</groupId><artifactId> Spring-webmvc</artifactid><version>${spring.version}</version></dependency><dependency><groupid> Org.springframework.data</groupid><artifactid>spring-data-mongodb</artifactid><version >1.2.0.release</version></dependency><dependency><groupid>org.springframework</ groupid><artifactid>spring-tx</artifactid><version>${spring.version}</version></ Dependency> <dependency><groupId>org.springframework</groupId><artifactId> Spring-test</artifactid><version>${spring.version}</version><scope>test</scope> <exclusions><exclusion><groupId>commons-logging</groupId><artifactId> commons-logging</artifactid></exclusion></exclusions></dependency><!--Json-- <dependency><groupid>org.codehaus.jackson</groupid><artifactid>jackson-core-lgpl</ artifactid><version>1.8.1</version></dependency><dependency><groupid>org.codehaus.jackson</groupid>< Artifactid>jackson-mapper-lgpl</artifactid><version>1.8.1</version></dependency> <dependency><groupId>net.sf.json-lib</groupId><artifactId>json-lib</artifactId> <version>${jsonlib.version}</version><classifier>jdk15</classifier></dependency> <!--end of Json--><!--logging--><dependency><groupid>org.slf4j</groupid>< Artifactid>slf4j-api</artifactid><version>${slf4j.version}</version></dependency> <dependency><groupId>org.slf4j</groupId><artifactId>jcl-over-slf4j</artifactId> <version>${slf4j.version}</version></dependency><dependency><groupid>org.slf4j </groupid><artifactid>slf4j-log4j12</artifactid><version>${slf4j.version}</version ></dependency> <d ependency><groupid>log4j</groupid><artifactid>log4j</artifactid><version>${ log4j.version}</version><scope>provided</scope></dependency><!--end of logging- <!--fileUpload--><dependency><groupid>commons-fileupload</groupid><artifactid> commons-fileupload</artifactid><version>1.2.2</version></dependency><!--End of FileUpload--><!--io--><dependency><groupid>commons-io</groupid><artifactid> commons-io</artifactid><version>2.4</version></dependency><dependency>< groupid>javax</groupid><artifactid>javaee-web-api</artifactid><version>7.0</ version><scope>provided</scope></dependency><dependency><groupid>junit</ Groupid><artifactid>junit</artifactid><version>${junit.version}</version><scope >test</scope></dependency><dependency><groupid>javax.servlet</groupid><artifactid>jstl</ artifactid><version>1.2</version></dependency></dependencies><build>< Finalname>springmvc_mongodb</finalname><plugins><plugin><groupid> Org.apache.tomcat.maven</groupid><artifactid>tomcat7-maven-plugin</artifactid><version >2.0-beta-1</version><configuration><uriEncoding>utf-8</uriEncoding><port> 8070</port><path>/</path></configuration></plugin></plugins></build> </project>

Spring-mvc.xml

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Mvc= "Http://www.springframework.org/schema/mvc" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns: context= "Http://www.springframework.org/schema/context" xsi:schemalocation= "http://www.springframework.or G/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www                 . Springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring- Mvc-3.1.xsd "><context:annotation-config/><!--enable spring to support automatic detection of components, such as the controller--><context for annotations: Component-scan base-package= "Com.jiaoxueyun.*.web.controller"/><bean class= " Org.springframework.web.servlet.view.InternalResourceViewResolver "><property name=" Viewclass "VAlue= "Org.springframework.web.servlet.view.JstlView"/><property name= "prefix" value= "/view"/>< Property name= "suffix" value= ". jsp"/></bean><!--start the Spring MVC annotation feature, complete the request and annotation POJO mappings--><bean class= " Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping "/><!--start the Spring JSON transformation-- ><bean class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >< Property Name= "Messageconverters" ><list><bean class= " Org.springframework.http.converter.StringHttpMessageConverter "/><bean class=" Org.springframework.http.converter.json.MappingJacksonHttpMessageConverter "><property name=" Supportedmediatypes "><list><value>application/json;charset=UTF-8</value></list>< /property></bean></list></property></bean><!--Information--><mvc:resources       mapping= "/resources/**" location= "/resources/"/><mvc:annotation-driven>   <mvc:message-converters> <bean class= "Org.springframework.http.converter.json.MappingJacksonHttpM              Essageconverter "> <property name=" objectmapper "ref=" Customobjectmapper "></property> </bean> </mvc:message-converters> </mvc:annotation-driven> </beans>

Applicationcontext.xml

<?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:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= " Http://www.springframework.org/schema/tx "xmlns:context=" Http://www.springframework.org/schema/context "xmlns:p= "http://www.springframework.org/schema/p" xmlns:cache= "Http://www.springframework.org/schema/cache" xmlns:jaxws=                    "Http://cxf.apache.org/jaxws" xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spring-beans-3.1.xsd HTTP://WWW.SPRINGFRAMEWORK.O Rg/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.                    SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-3.1.xsd          Http://www.springframework.org/schema/context                Http://www.springframework.org/schema/context/spring-context-3.1.xsd HTTP://WWW.SPRINGF                    Ramework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd Http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "> <!--annotations support--&GT;&L T;context:annotation-config/><!--Start the component scan and exclude the @controller component, which is scanned--><context by the SPRINGMVC profile: Component-scan base-package= "com" ></context:component-scan><!--properties File location--><bean id= " Annotationpropertyconfigurer "class=" Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer " ><property name= "Locations" ><list><value>classpath:config/properties/mongodb.properties </value><value>classpath:config/properties/common.properties</value><value>classpath: config/properties/log4j.properties</value></list></property></bean><!--<coNtext:property-placeholder location= "classpath:jdbc.properties"/>--><!--Entity mappings--><bean id= " Packagestoscan "class=" Org.springframework.beans.factory.config.ListFactoryBean "><property name=" SourceList "><list><value>com.yiyuwangluo.test.entity</value></list></property ></bean><!--Annotated transaction--><tx:annotation-driven transaction-manager= "TransactionManager"/>< Bean id= "Multipartresolver" class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver" >< Property Name= "Defaultencoding" value= "Utf-8" ></property></bean> <import resource= "classpath:/ Config/mongodb/mongodb.xml "/></beans>
Mongodb.xml

<?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:context= "Http://www.springframework.org/schema/context" xmlns:mongo= "Http://www.springframework.org/schema/data/mongo" xsi:schemalocation= "http//             Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd Http://www.springframework.org/schema/data/mongo HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/DATA/MONGO/SP Ring-mongo-1.0.xsd Http://www.springframework.org/schema/beans Http://www.springframework.org/sche Ma/beans/spring-beans-3.0.xsd "><!--loading MongoDB Property profile--><!--<context:property-placeholder location = "Classpath:config/properties/mongodb.properties"/>-->< defines the MONGO object!--, corresponding to the MONGO in the official MongoDB jar package, Replica-set set the IP address and port of the cluster replica--><mongo:mongo id= "MONGO" replica-set= "${mongo.hostport}" ><!--Settings for connection properties--><mongo:options connections-per-host= "${mongo.connectionsperhost}" Threads-allowed-to-block-for-connection-multiplier= "${mongo.threadsallowedtoblockforconnectionmultiplier}" connect-timeout= "${mongo.connecttimeout}" Max-wait-time= "${mongo.maxwaittime}" auto-connect-retry= "${  Mongo.autoconnectretry} "socket-keep-alive=" ${mongo.socketkeepalive} "socket-timeout=" ${mongo.socketTimeout} " slave-ok= "${mongo.slaveok}" write-number= "1" write-timeout= "0" write-fsync= "true"/></mongo:mongo>< Mongo:db-factory dbname= "Database" mongo-ref= "MONGO"/><bean id= "mongotemplate" class= " Org.springframework.data.mongodb.core.MongoTemplate "><constructor-arg ref=" MONGO "/><constructor-arg Name= "DatabaseName" value= "Db_mongo"/></bean></beans>
Log4j.properties

Log4j.rootlogger=info,stdout,filelog4j.appender.stdout=org.apache.log4j.consoleappender Log4j.appender.stdout.layout=org.apache.log4j.patternlayout log4j.appender.stdout.target= System.outlog4j.appender.stdout.layout.conversionpattern=%-d{yyyy-mm-dd hh\:mm\:ss,sss} [%c]-[%p]%m%n Log4j.appender.file=org.apache.log4j.dailyrollingfileappender log4j.appender.file.file=${spring_springmvc_ Jpa.root}/shirodemo.loglog4j.appender.file.layout=org.apache.log4j.patternlayout Log4j.appender.r.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss,sss} [%t] [%c] [%p]-%m% Nlog4j.logger.org.hibernate.tool.hbm2ddl=info


Mongodb.properties

mongo.hostport=127.0.0.1:27017mongo.connectionsperhost=8mongo.threadsallowedtoblockforconnectionmultiplier=4# Connection Timeout time mongo.connecttimeout=1000# wait time mongo.maxwaittime=1500mongo.autoconnectretry=truemongo.socketkeepalive= True#socket Timeout Time Mongo.sockettimeout=1500mongo.slaveok=true

Xml

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version= " 2.5 "><display-name>test</display-name><context-param><param-name> log4jconfiglocation</param-name><param-value>classpath:config/properties/log4j.properties</ param-value></context-param><!--Spring's log4j listener ******************************************-- <!--set the log4j profile path--><!--A watchdog thread scans for changes in configuration files every 60 seconds--><context-param><param-name> log4jrefreshinterval</param-name><param-value>600000</param-value></context-param>< listener><listener-class>org.springframework.web.util.log4jconfiglistener</listener-class></ listener><!--***************--><context-param><param-name>contextconfiglocation</ param-name><param-value>classpath:config/spring/applicationcontext.xml</param-value></ Context-param><listener><listener-class>org.springframework.web.context.contextloaderlistener </listener-class></listener><servlet><servlet-name>springdispatcher</servlet-name ><servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class><init-param ><param-name>contextconfiglocation</param-name><param-value>classpath:config/spring/ spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></ Servlet><servlet-mapping><servlet-name>springdispatcher</servlet-name><url-pattern> /</url-pattern></servlet-mapping><filter><filter-name>encodingfilter</filter-name ><filter-class>org.springFramework.web.filter.characterencodingfilter</filter-class><init-param><param-name>encoding </param-name><param-value> utf-8</param-value></init-param><init-param>< param-name>forceencoding</param-name><param-value> true </param-value></init-param> </filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/ **//*</url-pattern></filter-mapping><servlet-mapping> <servlet-name>default</         servlet-name> <url-pattern>*.jpg</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern> </servlet-mappin g> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.css& lt;/url-pattern> </servlet-mapping> <servlet-mapping> &LT;SERVLEt-name>default</servlet-name> <url-pattern>*.png</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.gif</url -pattern> </servlet-mapping></web-app>



Springmvc+mongodb+maven Project Building Configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.