eclipse maven创建web项目
生活随笔
收集整理的這篇文章主要介紹了
eclipse maven创建web项目
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
記錄地址
jdk設置及文件包miss
實例下載地址
創建SSM整合項目
一.使用Eclipse中的maven插件創建web項目
1:
2:
3:
4:
5:maven web項目創建成功。(去掉index.jsp文件重新創建jsp文件,報錯消失)
6.
7.
8.Eclipse創建一個動態web項目,將其中的web.xml配置文件拷貝到maven項目中,注意修改項目名稱。
二、添加xml配置
1.web.xml配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"><display-name>mybatis-spring02</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><!-- web容器啟動時根據contextConfigLocation配置的路徑讀取Spring的配置文件,然后啟動Spring --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 配置Springmvc所有的請求都要通過DispatcherServlet --><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc-servlet.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!-- 編碼utf-8 --><filter><filter-name>SpringEncodingFilter</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>SpringEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping> </web-app>?2.springmvc-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:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"><!-- 啟用Controller注解支持 --><mvc:annotation-driven></mvc:annotation-driven><!-- 配置一個簡單的靜態資源映射規則 --><mvc:resources location="static/" mapping="/static/**"></mvc:resources><!-- 掃描Controller包下面的類 --> <context:component-scan base-package="com.watermelon.*.controller"></context:component-scan><!-- InternalResourceViewResolver將視圖名映射為URL文件 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property><property name="prefix" value="/WEB-INF/jsp/"></property><property name="suffix" value=".jsp"></property></bean> </beans>3.mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration><settings><setting name="logImpl" value="LOG4J"/><setting name="cacheEnabled" value="true"/><setting name="mapUnderscoreToCamelCase" value="true"/><setting name="aggressiveLazyLoading" value="false"/></settings></configuration>4.log4j.properties
### Global logging configuration log4j.rootLogger=ERROR, stdout### Uncomment for MyBatis logging log4j.logger.com.watermelon.web.mapper=TRACE### Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n5.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:mybatis-spring="http://mybatis.org/schema/mybatis-spring"xsi:schemaLocation="http://www/springframework.org/schema/context http://www/springframework.org/schema/context/spring-context.xsdhttp://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"><!--spring --><context:component-scan base-package="com.watermelon.web.service.impl"/> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="addToConfig" value="true"/><property name="basePackage" value="com.watermelon.web.mapper"/></bean><!-- spring自動掃描 包下面的帶注解的類,并注冊到Sping的bean容器中 service.impl<context:component-scan base-package="com.watermelon.web.service.impl"></context:component-scan>--><!-- mybatis-spring:scan 會掃描com.watermelon.dao包下面的所有接口當作Spring的bean配置 <mybatis-spring:scan base-package="com.watermelon.web.mapper"/>--><bean id="dataSource" class="org.apache.ibatis.datasource.pooled.PooledDataSource"><property name="driver" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql://localhost:3306/simple"/><property name="username" value="root"/><property name="password" value="123456"/></bean><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="configLocation" value="classpath:mybatis-config.xml"/><property name="dataSource" ref="dataSource"/><property name="mapperLocations"><array><value>classpath:com/watermelon/web/mapper/*.xml</value></array></property><property name="typeAliasesPackage" value="com.watermelon.web.model"/></bean><!-- Spring aop事務 --><aop:aspectj-autoproxy/><aop:config><aop:pointcut id="appService" expression="execution(* com.watermelon.*.service..*Service*.*(..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="appService"/></aop:config><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="select*" read-only="true"/><tx:method name="find*" read-only="true"/><tx:method name="get*" read-only="true"/><tx:method name="*"/></tx:attributes></tx:advice><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean></beans>項目結構:
轉載于:https://www.cnblogs.com/watermelonban/p/7614442.html
總結
以上是生活随笔為你收集整理的eclipse maven创建web项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 源码,反码和补码
- 下一篇: 20170930-构建之法:现代软件工程