SpringMVC+Spring+Mybatis配置的簡要總結

mameng1998發表於2018-03-28

網上關於SpringMVC+Spring+Mybatis配置的文章有很多,這裡就不在詳細描述了,本文的重點是對這一配置的簡要總結。

1 web.xml

在web.xml中書寫 

       <context-param>

<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-config.xml</param-value>

</context-param>

        <servlet>
<servlet-name>report</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-config-web.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>report</servlet-name>
<url-pattern>/</url-pattern>

</servlet-mapping>

2 spring-config.xml

       <bean id="configProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:conf/*.properties</value>
</list>
</property>

</bean>

        <bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties" />
</bean>

        <import resource="spring-config-datasource-dbcp.xml" />

2.1 spring-config-datasource-dbcp.xml

        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath:sqlmap/*mapper.xml"/>
        <property name="typeAliasesPackage" value="com.jd.eps.ediws.domain"/>
        <property name="configLocation"  value="classpath:mybatis-config.xml"/>
    </bean>

    <bean name="mapperScannerConfigurer" 

                  class="org.mybatis.spring.mapper.MapperScannerConfigurer">

        <property name="basePackage" value="com.jd.eps.ediws.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>

     </bean>

3 spring-config-web.xml

     檢視解析的配置等

相關文章