SSM环境配置

SSM环境配置必要的文件:applicationContext.xml,db.properties,springmvc-config.xml

一般建议将这些文件放在resources文件夹下,而且这些是命名规范,也就是说是不可以改名的!!

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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-4.3.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

    <!--   spring + Mybatis的整合      -->

    <!-- 1.  配置数据库相关的参数  -->
    <context:property-placeholder location="classpath:db.properties" />

    <!-- 2. 配置数据源   -->
    <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}" />
        <property name="maxPoolSize" value="30"/>
        <property name="minPoolSize" value="2"/>
    </bean>

    <!--  3. 配置SQLSessionFactory环境   -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 注入数据库连接池                -->
        <property name="dataSource" ref="dataSource"/>
        <!-- 扫描bean,使用别名      -->
        <property name="typeAliasesPackage" value="com.zrgj.bean"></property>
        <!--  配置加载映射文件       -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>

       <!-- 分页配置 -->
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <props>
                            <prop key="helperDialect">mysql</prop>
                            <prop key="reasonable">true</prop>
                        </props>
                    </property>
                </bean>
            </array>
        </property>
    </bean>

    <!--  4.  自动生成dao,mapper       -->
    <!--  配置扫描dao接口包,动态实现dao接口,注入到Spring容器中   -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--  给出需要扫描的dao的接口包           -->
        <property name="basePackage" value="com.zrgj.dao"/>
        <!--  注入sqlsessionfactory       -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

    <!--  扫描整个包  -->
    <context:component-scan base-package="com.zrgj"/>


    <!--  5. 配置事物管理器   -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!--  6. 开启事物注解      -->
    <tx:annotation-driven></tx:annotation-driven>


</beans>

db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/java
jdbc.username=root
jdbc.password=123456

log4j.properties

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# 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%n

springmvc-config.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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-4.3.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">


    <!--  1. 注解扫描位置   -->
    <context:component-scan base-package="com.zrgj.controller"/>

    <!--  2. 配置映射器和适配器   -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>

    <!--  3. 视图解析器  -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>


    <!--4.配置拦截器-->
    <mvc:interceptors>
        <mvc:interceptor>
            <!--拦截所有的mvc控制器-->
            <mvc:mapping path="/**"/>

            <!--mvc:exclude-mapping - 是另一种拦截,他可以在你后来测试中对某一个页面不拦截-->
            <mvc:exclude-mapping path="/userInfoController/doLigin.do"/>
            <!--告诉使用哪个拦截器-->
            <bean class="com.zrgj.interceptor.LoginInterceptor"/>

        </mvc:interceptor>
    </mvc:interceptors>


</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要配置SSM项目在Tomcat中,你可以按照以下步骤进行操作。首先,确保你已经安装并配置好了Tomcat服务器。你可以通过查看Tomcat的安装路径来确认它的位置。接下来,将打包好的war文件放入Tomcat服务器的webapps目录中。然后,启动Tomcat服务器,你可以使用命令`cd /usr/local/tomcat/webapps`进入Tomcat的目录,然后使用`./startup.sh`命令启动Tomcat。如果你想关闭Tomcat服务器,你可以使用`./shutdown.sh`命令。这样,你就成功地将SSM项目配置在了Tomcat服务器中。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ssm项目搭建(tomcat配置)详解](https://blog.csdn.net/jia814583973/article/details/103398966)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [SSM项目部署(环境配置+打成WAR包+TOMCAT部署)](https://blog.csdn.net/WDH_05/article/details/121619133)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值