Learn extjs5 with me (join 27--server web,spring,hibernate configuration file)

Source: Internet
Author: User
Tags system log

Learn extjs5 with me (join 27--server web,spring,hibernate configuration file)
when we created the project earlier, it was a Java Web project, and now we need to join the Spring,hibernate,sqlserver connected jar package and join the configuration file in the project. Spring I'm using version 3.1, Hibernate uses 3.0, specific jar packages and some additional packages, please download them and add them to the project. (All the jar packages are available in the demo software provided in my previous blog)
First, add some package in the SRC of Java resources. Create files Hibernate.cfg.xml and log4j.properties in the SRC directory.

the configuration file for Hibenate is as follows:/application5.01/src/hibernate.cfg.xml (using a SQL Server database is also possible with a different database.) )
<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "Http://hibernate.sourcefor Ge.net/hibernate-configuration-3.0.dtd ">
  
System Log configuration file:/application5.01/src/log4j.properties.
Log4j.rootcategory=error, consolelog4j.appender.console= org.apache.log4j.consoleappenderlog4j.appender.console.layout= org.apache.log4j.patternlayoutlog4j.appender.console.layout.conversionpattern=%-4r [%t]%-5p%c%x-%m% nlog4j.logger.org.hibernate=errorlog4j.logger.org.hibernate.sql=errorlog4j.logger.com.jfok= Errorlog4j.logger.org.springframework=error#log4j.category.org.hibernate.type=debug

Second, modify the Web. xml file to add Spring settings. you need to modify Web. XML in the Web-inf directory and add two spring configuration files Applicationcontext.xml and Dispatcherservlet-servlet.xml.

Web. xml File Contents:
<?xml version= "1.0" encoding= "UTF-8"? ><web-app 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" version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" ><!--Spring Listener--><listener><listener-class> org.springframework.web.context.contextloaderlistener</listener-class></listener><!--Spring Configuration file Address--><context-param><param-name>contextconfiglocation</param-name><param-value> /web-inf/applicationcontext.xml</param-value></context-param><!--Servlets--><!--Spring MVC , its configuration file is <servlet-name>-servlet.xml, here is "Dispatcherservlet-servlet.xml"--><servlet>< Servlet-name>dispatcherservlet</servlet-name><servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class><load-on-startup>1</ Load-on-startup></servlet><servlet-mapping><servlet-name>dispatcherservlet</servlet-name><url-pattern>*.do</ url-pattern><!--used to match calls such as/rest/module/remove.do/{id}--><url-pattern>/rest/*</url-pattern> </servlet-mapping><!--Character set encoding filter to prevent some garbled--><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><!--Default page to serve --><welcome-file-list><welcome-file>/index.jsp</welcome-file></welcome-file-list ><session-config><session-timeout>180</session-timeout></session-config><jsp-config>< jsp-property-group><url-pattern>*.jsp</url-pattern><trim-directive-whitespaces>true</ Trim-directive-whitespaces></jsp-property-group></jsp-config></web-app>

content of 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:p= "http://www.springframework.org/schema/p" 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-3.1.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/ Spring-tx-3.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-3.1.xsd "><context:annotation-config/><context:component-scan base-package=" Com.jfok " ><!--exclude the control layer and scan only the class of the DAO layer that generated the service layer--><context:exclude-filter type= "annotation" expression= " Org.springframework.stereotype.Controller "/></context:component-scan><tx:annotation-driven Transaction-manager= "TransactionManager" PROxy-target-class= "true"/><!--Spring is used to replace Hibernatesessionfactory.java sessionfactory--><bean id= " Sessionfactory "class=" Org.springframework.orm.hibernate3.LocalSessionFactoryBean "><property name=" Configlocation "value=" Classpath:hibernate.cfg.xml "></property></bean><!--transaction manager--><bean Id= "TransactionManager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" ><property Name= "Sessionfactory" ><ref local= "Sessionfactory"/></property></bean></beans>


content of Dispatcherservlet-servlet.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:p= "http://www.springframework.org/schema/p" xmlns:mvc= " Http://www.springframework.org/schema/mvc "xmlns:context=" Http://www.springframework.org/schema/context "xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.1.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/ Spring-mvc-3.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-3.1.xsd ><!--①: Scans all classes in a Web package to complete bean creation and automatic dependency injection, partitioning only classes labeled @controller, which are the control layers of MVC- ><context:component-scan base-package= "Com.jfok" use-default-filters= "false" ><context:include-filter type= "Annotation" expression= "Org.springframework.stereotype.Controller"/></context:component-scan> <!--②: Start Spring MVC annotation function, complete the request and annotation Pojo mapping--><mvc:annotation-driven/><beanclass= " Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping "/><beanclass=" Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter "/><beanclass=" Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter "></bean><!--Configure the Multipart resolver--><bean id= "Multipartresolver" class= " Org.springframework.web.multipart.commons.CommonsMultipartResolver "><!--one of the properties available; The maximum file size in bytes--><property name= "maxuploadsize" value= "10000000"/></bean></beans >
(due to the development of the spring annotation annotations used, the configuration file is not modified in the future development process.) )
Third, renamed Index.html to index.jsp.
Iv. Release the project in Tomcat. If there is no error message at run time, then all configuration and jar packages are correct.
Enter the URL in the browser: http://localhost:8888/app/, you should display the original page.

at this point the development environment is basically built, the following is to join a function.
PS: Because I use spring and spring MVC only as a simple configuration file and using the markup language to develop, for this aspect of the deep problem I will not, if there is a problem in the construction process, please try to resolve the issue.

Learn extjs5 with me (join 27--server web,spring,hibernate configuration file)

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.