我正在开发tomcat 7中的网站(春季3.1.1),但它给出了错误
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
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5017)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5531)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

我试图多次解决此错误,但失败了。我该如何解决这个错误?我需要你的帮助。
这是我的SqlMapConfig.xml,applicationContext和我的root-context。
我的SqlMapConfig.xml(config / SqlMapConfig.xml)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="BoardDao">
<select id="selectList" parameterType="map" resultType="BoardCommand">
SELECT
seq,
writer,
title,
content,
pwd,
hit,
regdate,
filename
FROM (
SELECT
a.*,
rownum rnum
FROM (
SELECT
*
FROM springboardtest
<where>
<if test ="keyWord != '' and keyField =='title'">
title like '%' ||#{keyWord}||'%'
</if>
<if test ="keyWord != '' and keyField =='writer'">
writer like '%' ||#{keyWord}||'%'
</if>
<if test ="keyWord != '' and keyField =='content'">
content like '%' ||#{keyWord}||'%'
</if>
<if test ="keyWord != '' and keyField =='all'">
content like '%' ||#{keyWord}||'%' or
title like '%' ||#{keyWord}||'%' or
writer like '%' ||#{keyWord}||'%'
</if>
</where>
ORDER BY seq desc)a)
<![CDATA[
WHERE rnum >= #{start} AND rnum <= #{end}
]]>
</select>
<select id="selectCount" parameterType="map" resultType="Integer">
SELECT
count(*)
FROM springboardtest
<where>
<if test ="keyWord != '' and keyField =='title'">
title like '%' ||#{keyWord}||'%'
</if>
<if test ="keyWord != '' and keyField =='writer'">
writer like '%' ||#{keyWord}||'%'
</if>
<if test ="keyWord != '' and keyField =='content'">
content like '%' ||#{keyWord}||'%'
</if>
<if test ="keyWord != '' and keyField =='all'">
content like '%' ||#{keyWord}||'%' or
title like '%' ||#{keyWord}||'%' or
writer like '%' ||#{keyWord}||'%'
</if>
</where>
</select>
</mapper>
&#13;
我的applicationContext(config / 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>
&#13;
和我的root-context
<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">
<!-- Root Context: defines shared resources visible to all other web components -->
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:config/oracle.properties</value>
</property>
</bean>
<!--1. pom.xml commons-dbcp.jar -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<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>
<!--2. JDBC 드라이버 연동 & URL커넥션 pom.xml spring-jdbc.jar -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 컴포넌트 어노테이션 스캔 -->
<context:component-scan base-package="com.blogboard" />
<!-- messageSource 지정 -->
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages.label</value>
<value>messages.validation</value>
</list>
</property>
</bean>
<!-- Exception 설정 -->
<bean
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.Exception">pageError</prop>
</props>
</property>
</bean>
<!-- viewResolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/boardView/" />
<property name="suffix" value=".jsp" />
<property name="order" value="1" />
</bean>
<!-- 파일 다운로드 -->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"
p:order="0" />
<!-- 파일 업로드 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="52428800" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
</beans>
&#13;
答案 0 :(得分: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>
我认为,这就是为什么不能建立。
答案 1 :(得分:1)
正如jamesBlake正确提到的,配置文件是配置。您提供映射器文件作为配置,ibatis无法将其解析为配置。
配置是您定义ibatis设置的文件和可在mapper文件中使用的别名(如果有)
Mapper文件是您实际编写查询的文件。您可以拥有任意数量的映射器文件。