日期:2014-05-17  浏览次数:21032 次

对已有程序进行了aspectj的整合

自从前几天发布了一个版本后,我就开始对ostocy-jshop做一些优化,让代码的耦合性减少。我就找到了aspectj在看了一些资料以后对其进行了整合。

简单的说下步骤和整合的功能代码吧

?

1,在eclipse中安装aspectj插件,找到help-=install new software 输入http://download.eclipse.org/tools/ajdt/36/update 这个地址。选择第一个安装即可。

?

?

?

2,把项目转换到aspectj模式下

?

右键项目--configuratie--有一个covert to aspectj?

?

3,看下spring的配置文件吧?

?

?

<?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:component-scan>
	<context:annotation-config />
	<context:property-placeholder location="classpath*:*.properties" />

	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close">
		<property name="driverClass" 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" class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="host" 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"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
		destroy-method="close">
		<property name="dataSource">
			<ref bean="dataSource" />
		</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>
				<