玖零定制问题修复
2016-01-11 13:05:47
跟着和尚一步一步搭建spring mvc+springdata jpa+mybatis+shiro+bootstrap项目(三)
`事隔几天,跟着和尚一步一步搭建springmvc+springdata-jpa+mybatis+shiro+bootstrap项目(三)也将开始了吧,原因和尚在对于整合jpa,mybatis那里耽搁了许久的时间,现在把最新的配置信息给发出来撒,这次我们配置2个文件,也就是整合jpa,mybatis的
SpringContext-mybatis.xml 用于配置mybaits
SpringContext-jpa.xml 用于配置jpa
废话不多说 贴代码 撸起
SpringContext-mybatis.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-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/cache http://www.springframework.org/schema/cache/spring-cache-4.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> <!-- 定义SqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="typeAliasesPackage"> <value>com.monk.*.entity</value> </property> </bean> <!-- 浏览自动注入mapper的包 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.monk.*.mappers" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean> <!--定义事务 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- AOP配置数据事务管理,也可以采用注解方式,也可以写在LoggerAspect里面 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="query*" read-only="true" /> <tx:method name="get*" read-only="true" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <!-- 对子类业务逻辑层实施事务 --> <aop:config proxy-target-class="true"> <aop:pointcut id="serviceOperation" expression="execution(* com.monk.*.service.impl.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" /> </aop:config> <!-- 注解方式的事务拦截器 开启 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> </beans>
SpringContext-jpa.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:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <!-- 指定数据源 --> <property name="dataSource" ref="dataSource" /> <!-- 指定Entity实体类包路径 --> <property name="packagesToScan"> <list> <value>com.monk.*.entity</value> </list> </property> <!-- 指定JPA属性;如Hibernate中指定是否显示SQL的是否显示、方言等 --> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <!-- 是否生成ddl文件 --> <property name="generateDdl" value="true" /> <!-- 是否展示sql --> <property name="showSql" value="false" /> <!-- 必要的数据库库使用的详细信息 --> <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" /> <!-- mysql,自行选择 --> <property name="database" value="MYSQL"/> </bean> </property> <property name="jpaProperties"> <props> <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop> <prop key="net.sf.ehcache.configurationResourceName">spring/SpringContext-cache.xml</prop> <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <!-- Spring Data Jpa配置 --> <!-- 配置 启用扫描并自动创建代理的功能 factory-class="com.monk.base.jpa.PeakJpaRepositoryFactory"自己定义的bean注解方式,可以不写,直接注解所有包下的 --> <jpa:repositories base-package="com.monk.*.dao" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager" factory-class="com.monk.base.jpa.PeakJpaRepositoryFactory"> </jpa:repositories> <!-- Jpa 事务配置 --> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <!-- 开启注解事务 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> </beans>
shiro 配置需要等用户等功能OK后才开始插入,现在插入没有任何意义
小伙伴门现在先看下基础的启动吧
还算不错哦,已经插入成功的哦
下次将配置shiro工作,至此跟着和尚一步一步搭建项目已经可以正常的玩起了,骚年们,去整合你的项目吧
在配置时候需要注意的地方 注解一定要开启哦,要不拿啥去让系统知道我们要做什么呢,欢迎关注群:462067739,跟着和尚一步一步搭建springmvc+spring-data-jpa+mybatis+shiro+bootstrap 里面和尚会不断的更新 项目最近进度,并且帮助大家一起调试我们的项目
评论
最近浏览
mjzxcyypp LV13
2020年4月17日
大大大坏蛋
2019年9月25日
暂无贡献等级
modesty LV1
2019年6月14日
头晕脑壳疼 LV6
2018年12月9日
小范馆
2018年4月25日
暂无贡献等级
nchulucifer LV1
2018年4月22日
程序猿全敏 LV29
2018年4月13日
AmazeCode
2018年4月10日
暂无贡献等级
xiaozhou18 LV2
2018年1月8日
huxingjie2018 LV2
2017年12月27日