欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SSH配置文件

程序员文章站 2022-04-30 10:02:47
...

1.pom依赖

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

com.hik
ssh03
1.0-SNAPSHOT
war

ssh03 Maven Webapp

http://www.example.com

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<spring.Version>4.3.1.RELEASE</spring.Version>
<hibernate.Version>4.3.5.Final</hibernate.Version>
<jstl.Version>1.2</jstl.Version>
<taglib.Version>1.1.2</taglib.Version>
<servlet.Version>3.0-alpha-1</servlet.Version>
<json.Version>1.9.13</json.Version>
<jackson.Version>2.5.0</jackson.Version>
<mysql.Version>8.0.15</mysql.Version>
<c3p0.Version>0.9.1.2</c3p0.Version>
<log4j.Version>1.2.17</log4j.Version>
<fileupload.Version>1.3.1</fileupload.Version>
<lombok.Version>1.16.10</lombok.Version>



junit
junit
4.11
test



org.springframework
spring-beans
spring.Version&lt;/version&gt;&lt;/dependency&gt;&lt;dependency&gt;&lt;groupId&gt;org.springframework&lt;/groupId&gt;&lt;artifactId&gt;springcore&lt;/artifactId&gt;&lt;version&gt;{spring.Version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-core&lt;/artifactId&gt; &lt;version&gt;{spring.Version}


org.springframework
spring-context
spring.Version&lt;/version&gt;&lt;/dependency&gt;&lt;dependency&gt;&lt;groupId&gt;org.springframework&lt;/groupId&gt;&lt;artifactId&gt;springorm&lt;/artifactId&gt;&lt;version&gt;{spring.Version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-orm&lt;/artifactId&gt; &lt;version&gt;{spring.Version}



org.springframework
spring-web
spring.Version&lt;/version&gt;&lt;/dependency&gt;&lt;dependency&gt;&lt;groupId&gt;org.springframework&lt;/groupId&gt;&lt;artifactId&gt;springwebmvc&lt;/artifactId&gt;&lt;version&gt;{spring.Version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt; &lt;version&gt;{spring.Version}



org.hibernate
hibernate-core
hibernate.Version&lt;/version&gt;&lt;/dependency&gt;&lt;!hibernate,&gt;&lt;dependency&gt;&lt;groupId&gt;org.hibernate&lt;/groupId&gt;&lt;artifactId&gt;hibernateehcache&lt;/artifactId&gt;&lt;version&gt;{hibernate.Version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- hibernate 缓存, 视情况添加--&gt; &lt;dependency&gt; &lt;groupId&gt;org.hibernate&lt;/groupId&gt; &lt;artifactId&gt;hibernate-ehcache&lt;/artifactId&gt; &lt;version&gt;{hibernate.Version}



jstl
jstl
jstl.Version&lt;/version&gt;&lt;/dependency&gt;&lt;dependency&gt;&lt;groupId&gt;taglibs&lt;/groupId&gt;&lt;artifactId&gt;standard&lt;/artifactId&gt;&lt;version&gt;{jstl.Version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;taglibs&lt;/groupId&gt; &lt;artifactId&gt;standard&lt;/artifactId&gt; &lt;version&gt;{taglib.Version}


javax.servlet
servlet-api
servlet.Version&lt;/version&gt;&lt;scope&gt;provided&lt;/scope&gt;&lt;/dependency&gt;&lt;!DataBasemysql&gt;&lt;dependency&gt;&lt;groupId&gt;mysql&lt;/groupId&gt;&lt;artifactId&gt;mysqlconnectorjava&lt;/artifactId&gt;&lt;version&gt;{servlet.Version}&lt;/version&gt; &lt;scope&gt;provided&lt;/scope&gt; &lt;/dependency&gt; &lt;!-- DataBase数据库连接 mysql包--&gt; &lt;dependency&gt; &lt;groupId&gt;mysql&lt;/groupId&gt; &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt; &lt;version&gt;{mysql.Version}



c3p0
c3p0
c3p0.Version&lt;/version&gt;&lt;/dependency&gt;&lt;!json使springMVCjson,&gt;&lt;dependency&gt;&lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;&lt;artifactId&gt;jacksonmapperasl&lt;/artifactId&gt;&lt;version&gt;{c3p0.Version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- json数据 使springMVC可以返回json值 ,视情况添加--&gt; &lt;dependency&gt; &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt; &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt; &lt;version&gt;{json.Version}



com.fasterxml.jackson.core
jackson-core
jackson.Version&lt;/version&gt;&lt;/dependency&gt;&lt;dependency&gt;&lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;&lt;artifactId&gt;jacksonannotations&lt;/artifactId&gt;&lt;version&gt;{jackson.Version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt; &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt; &lt;version&gt;{jackson.Version}


com.fasterxml.jackson.core
jackson-databind
jackson.Version&lt;/version&gt;&lt;/dependency&gt;&lt;!log4j,&gt;&lt;dependency&gt;&lt;groupId&gt;log4j&lt;/groupId&gt;&lt;artifactId&gt;log4j&lt;/artifactId&gt;&lt;version&gt;{jackson.Version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- log4j配置, 视情况添加--&gt; &lt;dependency&gt; &lt;groupId&gt;log4j&lt;/groupId&gt; &lt;artifactId&gt;log4j&lt;/artifactId&gt; &lt;version&gt;{log4j.Version}



commons-fileupload
commons-fileupload
fileupload.Version&lt;/version&gt;&lt;/dependency&gt;&lt;!lombok&gt;&lt;dependency&gt;&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;&lt;artifactId&gt;lombok&lt;/artifactId&gt;&lt;version&gt;{fileupload.Version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- lombok插件导包--&gt; &lt;dependency&gt; &lt;groupId&gt;org.projectlombok&lt;/groupId&gt; &lt;artifactId&gt;lombok&lt;/artifactId&gt; &lt;version&gt;{lombok.Version}
provided



ssh03



maven-clean-plugin
3.1.0



maven-resources-plugin
3.0.2


maven-compiler-plugin
3.8.0


maven-surefire-plugin
2.22.1


maven-war-plugin
3.2.2


maven-install-plugin
2.5.2


maven-deploy-plugin
2.8.2




2.jdbc.properties
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/syk1?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root

3.springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>

<mvc:annotation-driven/>
<!--扫描controller层在spring中不在扫描-->
<context:component-scan base-package="com.baidu.controller"/>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="views/"/>
    <property name="suffix" value=".jsp"/>
</bean>
<!--&lt;!&ndash;配置拦截器&ndash;&gt;-->
<!--<mvc:interceptors>-->
<!--<mvc:interceptor>-->
<!--&lt;!&ndash;配置拦截所有请求&ndash;&gt;-->
<!--<mvc:mapping path="/**"/>-->
<!--&lt;!&ndash;配置拦截器的位置&ndash;&gt;-->
<!--<bean class="这里写拦截器的位置"></bean>-->
<!--</mvc:interceptor>-->
<!--</mvc:interceptors>-->

4.aplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- 引入外部属性文件=============================== -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--在扫描时排除Controller-->
<context:component-scan base-package="com.baidu.controller">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 配置C3P0连接池=============================== -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driver}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="user" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
</bean>

<!-- 配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <!-- 注入连接池 -->
    <property name="dataSource" ref="dataSource"/>
    <!-- 配置Hibernate的相关属性 -->
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
    </property>

    <!-- 引入映射文件 -->
    <property name="mappingResources">
        <list>
            <value>User.hbm.xml</value>
        </list>
    </property>
</bean>


<!-- 事物管理器配置  -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />

5.web.xml

Archetype Created Web Application org.springframework.web.context.ContextLoaderListener contextConfigLocation classpath:applicationContext.xml springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:springMVC.xml springmvc *.action encoding org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 encoding *.action