读书人

关于ostocy-jshop2.0升级到注脚版本的

发布时间: 2012-08-28 12:37:01 作者: rapoo

关于ostocy-jshop2.0升级到注解版本的过程总结

?

对于团队合作开发来说太多配置文件每次加入新方法都需要修改是很不好的,很容易造成svn的冲突。

?

这里来一个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:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="           http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd           http://www.springframework.org/schema/tx           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd          http://www.springframework.org/schema/context           http://www.springframework.org/schema/context/spring-context-2.5.xsd           http://www.springframework.org/schema/aop           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" default-autowire="byName"><aop:aspectj-autoproxy></aop:aspectj-autoproxy><context:component-scan base-package="com.jshop" /><context:annotation-config /><context:property-placeholder location="classpath*:*.properties" /><bean id="dataSource" value="${jdbc.driver}" /><property name="jdbcUrl" value="${jdbc.url}" /><property name="user" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /><property name="initialPoolSize" value="${pool.initialPoolSize}" /><property name="minPoolSize" value="${pool.minPoolSize}" /><property name="maxPoolSize" value="${pool.maxPoolSize}" /><property name="maxIdleTime" value="${pool.maxIdleTime}" /><property name="acquireIncrement" value="${pool.acquireIncrement}" /><property name="checkoutTimeout" value="${pool.checkoutTimeout}" /><property name="maxIdleTimeExcessConnections" value="${pool.maxIdleTimeExcessConnections}" /></bean><!-- 邮箱服务器配置 --><bean id="javamailsenderimpl" value="${email.host}"></property><property name="defaultEncoding" value="${email.defaultEncoding}"></property><property name="port" value="${email.port}"></property><property name="username" value="${email.username}"></property><property name="password" value="${email.password}"></property><property name="javaMailProperties"><props><prop key="mail.smtp.auth">${email.auth}</prop><prop key="mail.smtp.timeout">${email.timeout}</prop></props></property></bean><bean id="sessionFactory"/></property><property name="mappingDirectoryLocations">         <list>            <value>classpath:com/jshop/entity</value>         </list>       </property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect                                         </prop><prop key="hibernate.show_sql">true</prop></props></property></bean> <bean id="transactionManager"/></property></bean><aop:config><aop:advisor pointcut="execution(* com.jshop.action.service.*Service.*(..))" advice-ref="txAdvice"/></aop:config><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="get*" read-only="true"/><tx:method name="query*" read-only="true"/><tx:method name="find*" read-only="true"/><tx:method name="load*" read-only="true"/><tx:method name="*" rollback-for="Exception"/></tx:attributes></tx:advice> <bean id="hibernateTemplate" /></property></bean> <!-- 配置异步线程执行器 -->  <!-- 为异步线程执行器 进注入  --><bean id="taskExecutor"value="10"></property><!-- 设置最大池子的大小  --> <property name="maxPoolSize" value="30"></property></bean></beans>

?从上到下,依次的内容解释为

?接下来是摘录部分类的注解了

? ? Dao层

?

?

@Repository("articleCategoryTDaoImpl")public class ArticleCategoryTDaoImpl extends HibernateDaoSupport implements ArticleCategoryTDao {

?继承HibernateDaoSupport 就不用注入hibernateTemplate了

?

? ? ?Service 层

?

@Service("articleCategoryTServiceImpl")@Scope("prototype")public class ArticleCategoryTServiceImpl implements ArticleCategoryTService {@Resource(name="articleCategoryTDaoImpl")private ArticleCategoryTDaoImpl articleCategoryTDaoImpl;public ArticleCategoryTDaoImpl getArticleCategoryTDaoImpl() {return articleCategoryTDaoImpl;}

?

?

?

Action层@ParentPackage("jshop")

@Controller("articleCategoryTAction")public class ArticleCategoryTAction extends ActionSupport {@Resource(name = "articleCategoryTServiceImpl")private ArticleCategoryTServiceImpl articleCategoryTServiceImpl;

?

?

?

接下来是struts.xml了

?

<!--开发状态 -->      <constant name="struts.devMode" value="true" />    <!-- 配置文件重新加载 -->      <constant name="struts.configuration.xml.reload" value="true" />     <!-- convention类从新加载 -->      <constant name="struts.convention.classes.reload" value="true" />      <!-- 主题 -->      <constant name="struts.ui.theme" value="simple" /><constant name="struts.custom.i18n.resources" value="globalMessages" /><constant name="struts.i18n.encodeing" value="UTF-8" /><constant name="struts.convention.result.path" value="/" /> <package name="jshop" extends="json-default" ><interceptors><interceptor name="json" /><!-- 新增登录验证拦截器 --><interceptor name="authoritylogin" /><!-- 定义全局变量拦截器 是否允许用户注册多个商城信息 --><interceptor name="canuserregistermoreshopinfo"/><interceptor-stack name="jshopdefaultStack"><!-- 将登录验证拦截器加入默认的拦截器栈中 --><interceptor-ref name="authoritylogin"><param name="excludeMethods">adminlogin,uploadFiles,findAllCoupon,loginforAndroid,registerforAndroid</param></interceptor-ref><interceptor-ref name="defaultStack"></interceptor-ref><interceptor-ref name="json"></interceptor-ref></interceptor-stack></interceptors><default-interceptor-ref name="jshopdefaultStack" /><global-results><result name="login" type="redirect">/jshop/admin/jump.jsp</result><result name="isusercanregister">/usercenter/warning/warningmsg.jsp</result><result name="canuserregistermoreshopinfo">/jshop/admin/error/adminerror.jsp</result></global-results>       <!-- 验证码 --><action name="randomchecknum" style="text-align: left;">?

?

?

读书人网 >操作系统

热点推荐