在没有网络环境的时候,如何给spring 3.0加载dtd文件
在用到aspectj时候,调用了相关的
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE aspectj PUBLIC
"-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
在没有联网时就会报错无法解析xml文件,www.eclispe.org 无法找到host
请问如何解决???
没有人碰到过这种问题吗?不要用DTD用SCHEMA,SPRINGJAR包里有的,XML里声明正确就行,无需联网验证<preclass="brush:xml;toolbar:true;auto-links:false;">?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd">我是这样弄的这个是spring的beans的命名空间与我说的不是一回事,这个可以在spring的applicationcontext配置文件中应用到,还是谢谢
引用aspectj的dtd文件但是如果删除掉
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#F9F9F9;"><!DOCTYPEaspectjPUBLIC <spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#F9F9F9;">"-//AspectJ//DTD//EN""http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> 报如下错误:
cvc-elt.1:Cannotfindthedeclarationofelement'aspectj'.
不删除没有联网时就报<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#F9F9F9;">www.eclispe.org无法找到host
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#F9F9F9;">spring的jar包里包含aspectj的dtd声明文件?
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#F9F9F9;">具体怎么写请指教!
<preclass="brush:xml;toolbar:true;auto-links:false;"><?xmlversion="1.0"encoding="UTF-8"?><beans...xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="...http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd..."</beans>springaop包含aspectj各种切面等定义规则吧?这个只是spring的aop的schema啊,并没有包含aspectj的啊,这个明明空间是无法运用到aspectj上的,aop的pointcut等元素才是应用这个命名空间的,但是aspectj的不行,我试过了aop.xml
<preclass="brush:xml;toolbar:true;auto-links:false;"><!DOCTYPEaspectjPUBLIC"-//AspectJ//DTD//EN""aspectj.dtd"><aspectj><weaver><!--onlyweaveclassesinourapplication-specificpackages--><includewithin="demo.spring.aspectj. "/></weaver><aspects><!--weaveinjustthisaspect--><aspectname="demo.spring.aspectj.ProfilingAspect"/></aspects></aspectj>
aspect的配置文件中,把aspectj的dtd地址改成本地文件地址,我把aspectj.dtd文件和aop.xml放在相同的资源目录下
我将aspectj.dtd放到此包内,报如下错误CouldnotopenServletContextresource[/com/fujitsu/dtd/aspectj.dtd]用springjar里得我记得里面貌似有这个文件然后放到web-inf里引入即可还是没有什么办法吗,春节都过了啦!!!aop.xml默认是在META-INF目录下的吧?我把aop.xml和aspectj.dtd都放在META-INF目录下没有问题哎<arel="nofollow">http://download.csdn.net/detail/iq527/5066897
示例代码,一个maven工程,我把依赖也一起导出了.你看看有帮助没.0积分下载的-.-!
我自己结案吧一直没有人回答
在spring里面存在
spring.schemas
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsdhttp://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsdhttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd=org/springframework/aop/config/spring-aop-3.0.xsdhttp://www.springframework.org/schema/aop/spring-aop-3.1.xsd=org/springframework/aop/config/spring-aop-3.1.xsdhttp://www.springframework.org/schema/aop/spring-aop-3.2.xsd=org/springframework/aop/config/spring-aop-3.2.xsdhttp://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-3.2.xsd
spring在解析的时候会自动映射,mybatis也是同样道理
/OfflineentityresolverfortheMyBatisDTDs@authorClintonBegin/publicclassXMLMapperEntityResolverimplementsEntityResolver{privatestaticfinalMap<String,String>doctypeMap=newHashMap<String,String>();privatestaticfinalStringIBATIS_CONFIG_PUBLIC="-//ibatis.apache.org//DTDConfig3.0//EN".toUpperCase(Locale.ENGLISH);privatestaticfinalStringIBATIS_CONFIG_SYSTEM="http://ibatis.apache.org/dtd/ibatis-3-config.dtd".toUpperCase(Locale.ENGLISH);privatestaticfinalStringIBATIS_MAPPER_PUBLIC="-//ibatis.apache.org//DTDMapper3.0//EN".toUpperCase(Locale.ENGLISH);privatestaticfinalStringIBATIS_MAPPER_SYSTEM="http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd".toUpperCase(Locale.ENGLISH);privatestaticfinalStringMYBATIS_CONFIG_PUBLIC="-//mybatis.org//DTDConfig3.0//EN".toUpperCase(Locale.ENGLISH);privatestaticfinalStringMYBATIS_CONFIG_SYSTEM="http://mybatis.org/dtd/mybatis-3-config.dtd".toUpperCase(Locale.ENGLISH);privatestaticfinalStringMYBATIS_MAPPER_PUBLIC="-//mybatis.org//DTDMapper3.0//EN".toUpperCase(Locale.ENGLISH);privatestaticfinalStringMYBATIS_MAPPER_SYSTEM="http://mybatis.org/dtd/mybatis-3-mapper.dtd".toUpperCase(Locale.ENGLISH);privatestaticfinalStringMYBATIS_CONFIG_DTD="org/apache/ibatis/builder/xml/mybatis-3-config.dtd";privatestaticfinalStringMYBATIS_MAPPER_DTD="org/apache/ibatis/builder/xml/mybatis-3-mapper.dtd";static{doctypeMap.put(IBATIS_CONFIG_SYSTEM,MYBATIS_CONFIG_DTD);doctypeMap.put(IBATIS_CONFIG_PUBLIC,MYBATIS_CONFIG_DTD);doctypeMap.put(IBATIS_MAPPER_SYSTEM,MYBATIS_MAPPER_DTD);doctypeMap.put(IBATIS_MAPPER_PUBLIC,MYBATIS_MAPPER_DTD);doctypeMap.put(MYBATIS_CONFIG_SYSTEM,MYBATIS_CONFIG_DTD);doctypeMap.put(MYBATIS_CONFIG_PUBLIC,MYBATIS_CONFIG_DTD);doctypeMap.put(MYBATIS_MAPPER_SYSTEM,MYBATIS_MAPPER_DTD);doctypeMap.put(MYBATIS_MAPPER_PUBLIC,MYBATIS_MAPPER_DTD);}/ConvertsapublicDTDintoalocalone@parampublicIdThepublicidthatiswhatcomesafter"PUBLIC"
@paramsystemIdThesystemidthatiswhatcomesafterthepublicid.@returnTheInputSourcefortheDTD**@throwsorg.xml.sax.SAXExceptionIfanythinggoeswrong/@OverridepublicInputSourceresolveEntity(StringpublicId,StringsystemId)throwsSAXException{if(publicId!=null){publicId=publicId.toUpperCase(Locale.ENGLISH);}if(systemId!=null){systemId=systemId.toUpperCase(Locale.ENGLISH);}InputSourcesource=null;try{Stringpath=doctypeMap.get(publicId);source=getInputSource(path,source);if(source==null){path=doctypeMap.get(systemId);source=getInputSource(path,source);}}catch(Exceptione){thrownewSAXException(e.toString());}returnsource;}privateInputSourcegetInputSource(Stringpath,InputSourcesource){if(path!=null){InputStreamin;try{in=Resources.getResourceAsStream(path);source=newInputSource(in);}catch(IOExceptione){//ignore,nullisok}}returnsource;}}
当解析到dtd时自动映射成对应jar下面的文件,这样无需去网络获取
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。