2015-09-18 84 views
0

我開發的網站(春季3.1.1),但它給錯誤錯誤:org.springframework.web.context.ContextLoader - 上下文初始化到Tomcat 7失敗org.springframework.beans.factory.BeanCreationException

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed 
 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [config/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [config/SqlMapConfig.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.NullPointerException 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
 
\t at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
 
\t at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567) 
 
\t at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) 
 
\t at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) 
 
\t at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) 
 
\t at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) 
 
\t at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) 
 
\t at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5017) 
 
\t at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5531) 
 
\t at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
 
\t at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) 
 
\t at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) 
 
\t at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
 
\t at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
 
\t at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
 
\t at java.lang.Thread.run(Thread.java:745)

我試圖解決這個錯誤很多次,但失敗了。我怎樣才能解決這個錯誤?我需要你的幫助。

這裏是我的SqlMapConfig.xml,applicationContext和我的根上下文。

我SqlMapConfig.xml(配置/ SqlMapConfig.xml)

​​

我的ApplicationContext對象(配置/的applicationContext)

<?xml version="1.0" encoding="UTF-8"?> 
 
    
 
<beans xmlns="http://www.springframework.org/schema/beans" 
 
    xmlns:context="http://www.springframework.org/schema/context" 
 
    xmlns:p="http://www.springframework.org/schema/p" 
 
    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-3.0.xsd 
 
     http://www.springframework.org/schema/context 
 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 
 
    
 
    <!-- 프로퍼티 경로지정 ${}이걸로 프로퍼티를 사용할수 있게해준다. --> 
 
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
 
     <property name="locations"> 
 
      <list> 
 
       <value>classpath:config/oracle.properties</value> 
 
      </list> 
 
     </property> 
 
    </bean> 
 
    
 
    <!-- 커넥션 풀을 이용한 DataSource 설정 --> 
 
    <bean id="dataSource" 
 
     class="org.apache.commons.dbcp.BasicDataSource"> 
 
     <property name="driverClassName" value="${jdbc.driverClassName}"/> 
 
     <property name="url" value="${jdbc.url}"/> 
 
     <property name="username" value="${jdbc.username}"/> 
 
     <property name="password" value="${jdbc.password}"/> 
 
    </bean> 
 
    
 
     
 
    <!-- 마이바티즈 스프링연동 모듈 SQL 연동 --> 
 
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
 
      <property name="configLocation" value="classpath:config/SqlMapConfig.xml"/> 
 
      <property name="dataSource" ref="dataSource" /> 
 
    </bean> 
 
    
 
    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> 
 
     <constructor-arg ref="sqlSessionFactory"/> 
 
    </bean> 
 
      
 
</beans>

和我的根上下文

<beans xmlns="http://www.springframework.org/schema/beans" 
 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" 
 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
 
    http://www.springframework.org/schema/context 
 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 
 

 

 
\t <!-- Root Context: defines shared resources visible to all other web components --> 
 
\t <bean id="propertyPlaceholderConfigurer" 
 
\t \t class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
 
\t \t <property name="locations"> 
 
\t \t \t <value>classpath:config/oracle.properties</value> 
 
\t \t </property> 
 
\t </bean> 
 

 
\t <!--1. pom.xml commons-dbcp.jar --> 
 
\t <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
 
\t \t destroy-method="close"> 
 
\t \t <property name="driverClassName" value="${jdbc.driverClassName}" /> 
 
\t \t <property name="url" value="${jdbc.url}" /> 
 
\t \t <property name="username" value="${jdbc.username}" /> 
 
\t \t <property name="password" value="${jdbc.password}" /> 
 
\t </bean> 
 

 
\t <!--2. JDBC 드라이버 연동 & URL커넥션 pom.xml spring-jdbc.jar --> 
 
\t <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> 
 
\t \t <property name="dataSource" ref="dataSource" /> 
 
\t </bean> 
 

 
\t <!-- 컴포넌트 어노테이션 스캔 --> 
 
\t <context:component-scan base-package="com.blogboard" /> 
 

 
\t <!-- messageSource 지정 --> 
 
\t <bean id="messageSource" 
 
\t \t class="org.springframework.context.support.ResourceBundleMessageSource"> 
 
\t \t <property name="basenames"> 
 
\t \t \t <list> 
 
\t \t \t \t <value>messages.label</value> 
 
\t \t \t \t <value>messages.validation</value> 
 
\t \t \t </list> 
 
\t \t </property> 
 
\t </bean> 
 

 
\t <!-- Exception 설정 --> 
 
\t <bean 
 
\t \t class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> 
 
\t \t <property name="exceptionMappings"> 
 
\t \t \t <props> 
 
\t \t \t \t <prop key="java.lang.Exception">pageError</prop> 
 
\t \t \t </props> 
 
\t \t </property> 
 
\t </bean> 
 

 
\t <!-- viewResolver --> 
 
\t <bean 
 
\t \t class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
 
\t \t <property name="prefix" value="/WEB-INF/boardView/" /> 
 
\t \t <property name="suffix" value=".jsp" /> 
 
\t \t <property name="order" value="1" /> 
 
\t </bean> 
 

 
\t <!-- 파일 다운로드 --> 
 
\t <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" 
 
\t \t p:order="0" /> 
 

 
\t <!-- 파일 업로드 --> 
 
\t <bean id="multipartResolver" 
 
\t \t class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
 
\t \t <property name="maxUploadSize" value="52428800" /> 
 
\t \t <property name="defaultEncoding" value="UTF-8" /> 
 
\t </bean> 
 

 

 
</beans>

回答

1

配置爲配置,試圖從谷歌找到它。 它看起來像下面

<configuration> 
<settings> 
    <setting name="cacheEnabled"    value="true" /> 
    <setting name="multipleResultSetsEnabled" value="true" /> 
    <setting name="useColumnLabel"    value="true" /> 
    <setting name="useGeneratedKeys"   value="false" /> 
    <setting name="defaultExecutorType"   value="SIMPLE" /> 
    <setting name="defaultStatementTimeout"  value="25000" /> 
    <setting name="jdbcTypeForNull"    value="NULL" /> 
</settings> 

<typeAliases> 
</typeAliases> 

</configuration> 

,並檢查您的SqlSessionFactory bean的配置再次

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="configLocation" value="classpath:/configuration/mybatis-config.xml"/> 
     <property name="mapperLocations" value="classpath*:sample/config/mappers/**/*.xml" /> 
</bean> 

我認爲,這就是爲什麼不能建。

+0

感謝您的答覆。我會盡力找到並再次檢查我的豆。謝謝。 –

1

正如jamesBlake所說的,配置文件是配置。您正在提供映射器文件作爲配置,而ibatis無法將其解析爲配置。

配置中,可以定義你的ibatis的設置和別名(如果有的話)可以在映射文件中使用的文件

映射文件是您在實際編寫你的queries.You可以有很多的映射文件,如你想。

相關問題