获得解析异常

时间:2016-03-23 04:22:58

标签: java xml spring aop

<?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-2.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<!-- <context:annotation-config/>
<aop:aspectj-autoproxy />

 -->
 <bean name="triangle" class="springaop.service.model.Triangle">
 <property name="name" value="triagnle name"/>
 </bean>
  <bean name="circle" class="springaop.service.model.Circle">
 <property name="name" value="cirlce name"/>
 </bean>
  <bean name="shapeservice" class="springaop.service.model.Shapeservice" autowire="byname"/>

 </bean>

这是我的XML文件。

package springaop;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import springaop.service.Shapeservice;

public class Aopmain {

    public static void main(String[] args) {

   ApplicationContext  ctx = new ClassPathXmlApplicationContext("spring1.xml");

    Shapeservice shapeservice = ctx.getBean("shapeservice",Shapeservice.class);
    System.out.println(shapeservice.getCircle().getName());
    }

}

这是我的主要应用程序...请帮助解决这个问题......

Mar 23, 2016 9:31:47 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@b1a58a3: startup date [Wed Mar 23 09:31:47 IST 2016]; root of context hierarchy
Mar 23, 2016 9:31:48 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring1.xml]
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 20 in XML document from class path resource [spring1.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 93; cvc-enumeration-valid: Value 'byname' is not facet-valid with respect to enumeration '[default, no, byName, byType, constructor, autodetect]'. It must be a value from the enumeration.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at springaop.Aopmain.main(Aopmain.java:12)
Caused by: org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 93; cvc-enumeration-valid: Value 'byname' is not facet-valid with respect to enumeration '[default, no, byName, byType, constructor, autodetect]'. It must be a value from the enumeration.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:458)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3237)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processOneAttribute(XMLSchemaValidator.java:2832)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processAttributes(XMLSchemaValidator.java:2769)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2056)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(XMLSchemaValidator.java:766)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:356)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
    ... 14 more

我正在使用Spring 4和 aspectj1.8 / LIB / aspectjrt.jar / aspectj1.8 / LIB / aspectjweaver.jar / aopalliance-alpha1.jar / CGLIB的3.2.1.jar / ASM-4.1 / LIB / ASM-4.1.jar

3 个答案:

答案 0 :(得分:2)

您的代码中存在三个问题。 你还没有结束开始的豆子&#39;在你的spring配置文件中标记,而不是你保留了bean#39;在那里结束标记而不是&#39;豆类&#39;结束标签

另一个是:&#34;按名称自动装配&#34;需要keyWord&#39; byName&#39; &安培;不是&#39; byname&#39;。替换&#39; byname&#39;使用&#39; byName&#39;。

第三个是拼写错误: 在你的spring配置文件中,你有一个bean,即三角形&#39;其财产名称&#39;有价值&#39; triagnle name&#39;,这是拼写错误。也许它可能不会影响,但它可能会在未来的调整中影响你。 您可以将其更改回&#34;三角形名称&#34;。

答案 1 :(得分:1)

在这个bean定义中:

<bean name="shapeservice" class="springaop.service.model.Shapeservice" autowire="byname"/>

byname更改为byName。正确的定义应该是:

<bean name="shapeservice" class="springaop.service.model.Shapeservice" autowire="byName"/>

答案 2 :(得分:0)

我猜根标记<beans>没有匹配的结束标记</beans>。您已将</bean>作为xml中的结尾标记,将其更改为</beans>并查看该标记是否有效。

<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-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> ... </beans> - &gt;请注意XML中的匹配标记。