您的位置:首页 > 移动开发

springmvc+shiro简单配置及作用(applicationContext.XML springmvc部分)

2015-10-20 17:57 579 查看
1.<context:annotation-config /> 避免注解的声明,简化配置

2.<context:component-scan base-package="com.mvc.rest.*" /> 扫描指定包中的注解配置

3.datasource配置

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/config/jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="autoCommitOnClose" value="true"/>
<property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>
<property name="initialPoolSize" value="${cpool.minPoolSize}"/>
<property name="minPoolSize" value="${cpool.minPoolSize}"/>
<property name="maxPoolSize" value="${cpool.maxPoolSize}"/>
<property name="maxIdleTime" value="${cpool.maxIdleTime}"/>
<property name="acquireIncrement" value="${cpool.acquireIncrement}"/>
<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>
</bean>


4.sessionfactory配置

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>

<property name="hibernateProperties">
<value>
hibernate.dialect=${hibernate.dialect}
hibernate.hbm2ddl.auto=false
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.jdbc.use_streams_for_binary=true
hibernate.jdbc.batch_size=0
hibernate.jdbc.fetch_size=50
hibernate.current_session_context_class=org.springframework.orm.hibernate3.SpringSessionContext
</value>
</property>
<property name="packagesToScan">
<list>
<value>com.mvc.rest*</value>

</list>
</property>
</bean>


【注意packagesToScan的使用版本,若是版本更换了仍不能使用,还是重新下载jar包为好】

4.事务管理配置

<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<aop:config>
<aop:advisor pointcut="execution(* com.mvc.rest.*.*(..))" advice-ref="txAdvice" />
<aop:advisor pointcut="execution(* com.mvc.rest.core.*.*(..))" advice-ref="txAdvice" />
</aop:config>

<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="is*" read-only="true" />
<tx:method name="list*" read-only="true" />
<tx:method name="select*" read-only="true" />
<tx:method name="*" propagation="SUPPORTS"   />
</tx:attributes>
</tx:advice>
【注意理解txAdvice配置,方法名的定义要符合配置规范,若是有例外可以通过注解来配置】

5.其他配置

a.文件上传配置 【可设置最大文件上传限制,需要相关jar包支持,注意文件上传时通过MultipartFile接收上传的文件,也可以通过MultipartHttpServletRequest 获取filelist,但是使用MultipartHttpServletRequest 后,随文件上传的参数不能使用HttpServletRequest获取,它已经为null了被转化为了MultipartHttpServletRequest 】

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
b.json配置

c.使用restful风格时,对静态文件的配置

<mvc:resources location="/scripts/**" mapping="/scripts/"/>


d.对视图的渲染

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/view/" p:suffix=".jsp" />


e.

<mvc:default-servlet-handler/>
servlet在找页面时,走的是dispatcherServlet路线。找不到的时候会报404

加上这个默认的servlet时候,servlet在找不到的时候会去找静态的内容。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: