Spring_memo

20170531 Spring学习笔记--Spring配置文件和依赖注入

----------------------------------------------------------

apache:commons-logging-1.1.jar也需要

Spring-AOP遇到的问题2017/03/31

from:http://blog.csdn.net/kimifdw/article/details/7431088

这个是在spring中配置aop的中遇到的问题(可能相对于别人来说比较简单,但我还是想把它记下来):
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from class path resource [Application.xml] is invalid; nested exception is org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.

这个问题主要是说在操作XML配置文件的时候,配置文件一开始就没写正确,有几条配置无效。修改后,又出现了以下的问题:
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [Application.xml]; nested exception is Java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

这个问题是因为没有导入aopalliance.jar包,大家可以从http://mvnrepository.com/artifact/aopalliance/aopalliance去下载

通过以上一个简单的AOP的配置,其实也可以说明从官网中下载的spring包并不是很全,在今后的配置中需要更加注意,平时多注意收集

--------------------------------------------------------------------------

Pointcut is not well-formed: expecting 'name pattern' at character position

Pointcut is not well-formed: expecting 'name pattern' at character position  

配置aop报错:原因是配置切点表达式的时候报错了:

切点表达式配置方法:

切入点表达式的使用规则:

execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)

有“?”号的部分表示可省略的,modifers-pattern表示修饰符如publicprotected等,ret-type-pattern表示方法返回类型,declaring-type-pattern代表特定的类,name-pattern代表方法名称,param-pattern表示参数,throws-pattern表示抛出的异常。在切入点表达式中,可以使用*来代表任意字符,用..来表示任意个参数。

<aop:config proxy-target-class="false">
        <aop:aspect ref="corletPointCutTest">
            <aop:pointcut id="allRenderProcess"
                expression="execution(* com.hsbc.esf.requestprocessing.portlet.impl.PortletFrontController.doRenderService(..)) || execution(* com.hsbc.esf.requestprocessing.portlet.impl.PortletFrontController.processRenderRequest(..))||execution(* com.hsbc.esf.requestprocessing.portlet.impl.PortletFrontController.doActionService(..))" />
         <aop:before  method="checkPorletPoint" pointcut-ref="allRenderProcess"/>
        </aop:aspect>
    </aop:config>   


注意星号后面要有个空格

-----------------------------------------------------------------------

红色字体处表示AOP使用了aspectJ的表达方式,所以需要引入aspectJ的JAR包

  aopalliance-1.0.jar

  aspectjrt-1.7.4.jar

  aspectjweaver-1.7.4.jar

<?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:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-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/aop
            http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">

        <bean id="myAspect" class="main.java.aop.schema.MyAspect"></bean>
        <bean id="aspectBiz" class="main.java.aop.schema.AspectBiz"></bean>
        <aop:config>
            <aop:aspect id="myAspectAOP" ref="myAspect">
                <aop:pointcut id="myPointcut1" expression="execution(* main.java.aop.schema.AspectBiz.*(..))"/>
                <aop:before method="before" pointcut-ref="myPointcut1"/>
            </aop:aspect>
        </aop:config>
 </beans>

原文地址:https://www.cnblogs.com/charles999/p/6651779.html