SSH整合配置

需要三个文件,分别是 web.xml,springmvc的配置文件,spring和mybatis整合的配置文件

!!!为了便于管理这三个配置文件全部存放于Src目录下

①web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <!--Spring监听器,用于监听Tomcat启动-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <!--设置spring MVC配置文件位置-->
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    <!-- 配置Spring和mybatis整合配置文件位置-->
     <context-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>classpath:spring-mybatis.xml</param-value>
     </context-param>



    <!--字符编码过滤器-->
    <filter>
        <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

②spring mvc配置文件

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-4.1.xsd ">
    <!--配置启动spring MVC注解-->
    <context:annotation-config />
    <!-- 设置使用注解的类所在的包 -->
    <context:component-scan base-package="controller"/>
    <mvc:annotation-driven/>
    <!--配置视图解析器,设置前缀与后缀-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value= ""/>
        <property name="suffix" value= ".jsp"/>
    </bean>
<!--将处理完请求后返回的对象绑定到响应正文,即将对象序列化为Json-->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html; charset=UTF-8</value>
                            <value>application/json;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html; charset=UTF-8</value>
                            <value>application/json;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
            </list>
        </property>
    </bean>
</beans>

③spring和mybatis整合的配置文件

<?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:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context-4.1.xsd
  		http://www.springframework.org/schema/tx
  		http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
    <!--需要从component的文件所在目录-->
    <context:component-scan base-package="dao"/>
    <!--数据源中的账户密码的properties文件位置-->
    <context:property-placeholder location="classpath:database.properties" />
    <!--初始化数据源-->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  destroy-method="close">
        <!-- 初始化连接数量; -->
        <property name="initialSize" value="0" />
        <!-- 最大并发连接数 	-->
        <property name="maxActive" value="20" />

        <!-- 最大空闲连接数 -->
        <property name="maxIdle" value="20" />
        <!-- 最小空闲连接数 -->
        <property name="minIdle" value="0" />
        <!-- 最大等待时长 -->
        <property name="maxWait" value="60000" />
        <!-- 超过时间限制是否回收 -->
        <property name="removeAbandoned" value="true" />
        <!-- 超过时间限制多长; -->
        <property name="removeAbandonedTimeout" value="180"/>


        <!-- 数据源连接参数配置; -->
        <property name="username" value="${db.username}"/>
        <property name="url" value="${db.url}"/>
        <property name="password" value="${db.password}"/>
        <property name="driverClassName" value="${db.driver}"/>

    </bean>


    <!-- 配置SessionFactory 名字不能更改 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!--配置mapper映射文件所在位置-->
        <!-- <property name="mapperLocations" value="classpath:mapper/*.xml" /> -->
        <!--<property name="mapperLocations">-->
            <!--<list>-->
                <!--<value>classpath:mapper/*.xml</value>-->
            <!--</list>-->
        <!--</property>-->
    </bean>
    <!-- 自动扫描mapper接口,注入sqlSessionFactory 设置mapper接口所在的文件夹-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="mapper"/>
    </bean>

    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- <tx:annotation-driven transaction-manager="transactionManager"  proxy-target-class="true"/> -->
    <!-- 定义切面 -->
    <aop:config>
        <aop:pointcut expression="execution(* dao.*.* (..))" id="txPointCut"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
    </aop:config>

    <!-- 声明式事务 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="isValid" propagation="REQUIRED" read-only="true"/>
            <tx:method name="add" propagation="REQUIRED" read-only="true"/>
        </tx:attributes>
    </tx:advice>
</beans>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于IDEA的SSH配置,可以按照以下步骤进行配置: 1. 首先,确保你已经安装了Git,并且在IDEA的设置中配置了Git的路径。 2. 打开IDEA,选择File菜单中的Settings选项。 3. 在Settings窗口中,选择Version Control选项,然后选择Git。 4. 在Git配置页面中,点击"+"按钮添加你的Git仓库。输入你的仓库URL和认证信息,点击"Test"按钮验证连接是否成功。如果连接成功,点击"OK"按钮保存配置。 5. 接下来,选择File菜单中的Settings选项,然后选择Build, Execution, Deployment选项。 6. 在Build, Execution, Deployment页面中,选择Deployment选项,点击"+"按钮添加一个新的部署配置。 7. 在部署配置页面中,选择SFTP选项。填写你的主机名、用户名、密码和远程路径。 8. 点击"Test SFTP connection"按钮验证连接是否成功。如果连接成功,点击"OK"按钮保存配置。 9. 现在,你可以使用SSH功能来进行代码的版本控制和部署了。 提供了一个关于Spring与Struts2整合配置例子,该例子主要涉及到创建接口和接口实现类,并在applicationContext.xml中进行配置。但是,与SSH配置无关。 因此,如果您想要配置SSH,您需要按照上述步骤进行操作。这样就可以在IDEA中使用SSH功能了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [在IDEA中配置SSH环境](https://blog.csdn.net/weixin_45756488/article/details/121348227)[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_1"}}] [.reference_item style="max-width: 50%"] - *2* [java课程设计项目:基于SpringBoot的在线订餐系统.zip](https://download.csdn.net/download/qq_35831906/88222416)[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_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值