刚学spring,一开始就遇到个异常。
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [xml/1.xml]; nested exception is org.springframework.beans.FatalBeanException: Unable to load schema mappings from location [META-INF/spring.schemas]; nested exception is java.util.zip.ZipException: 拒绝访问。 我一共就干了3件事。加jar包aspectjrt.jaraspectjweaver.jarcglib-nodep-2.1_3.jarcommon-annotations.jarcommons-dbcp.jarcommons-logging.jarcommons-pool.jarlog4j-1.2.15.jarspring.jarspring-webmvc-struts.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
</beans>搞个main方法测一下。结果就报错public static void main(String[] args){
ApplicationContext ac = new ClassPathXmlApplicationContext(
"xml/1.xml");
}
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [xml/1.xml]; nested exception is org.springframework.beans.FatalBeanException: Unable to load schema mappings from location [META-INF/spring.schemas]; nested exception is java.util.zip.ZipException: 拒绝访问。 我一共就干了3件事。加jar包aspectjrt.jaraspectjweaver.jarcglib-nodep-2.1_3.jarcommon-annotations.jarcommons-dbcp.jarcommons-logging.jarcommons-pool.jarlog4j-1.2.15.jarspring.jarspring-webmvc-struts.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
</beans>搞个main方法测一下。结果就报错public static void main(String[] args){
ApplicationContext ac = new ClassPathXmlApplicationContext(
"xml/1.xml");
}
aspectjweaver.jar
cglib-nodep-2.1_3.jar
common-annotations.jar
commons-logging.jar
log4j-1.2.15.jar
spring.jar
简单的spring有这几个包够了。
将applicationContext.XML直接放在src在就行了。
然后
在程序中直接加载就行了
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext.xml");
既然是新手,就要学会动脑子,别那么懒。