S.K. Kang
S.K. Kang

Reputation: 43

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException

I am developing web-site(spring 3.1.1) in tomcat 7 but it is giving error

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)

I tried to solve this error many times but it failed. How can I solve this error? I need your help.

here are my SqlMapConfig.xml,applicationContext and my root-context.

my 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>

my 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>

and my 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>

Upvotes: 0

Views: 7384

Answers (2)

Azhar
Azhar

Reputation: 398

As jamesBlake rightly mentioned, configuration file is configuration. You are providing the mapper file as configuration and ibatis cannot parse it as configuration.

Configuration is file where you define your ibatis settings and alias (if any) which can be used in mapper files

Mapper file is one where you actually write your queries.You can have as many mapper files as you want.

Upvotes: 1

jamesBlake
jamesBlake

Reputation: 166

Configuration is configuration, try to find it out from google. It looks something like below

<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>

And check your sqlSessionFactory bean configuration again

<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>

I think, that's why fail to build.

Upvotes: 1

Related Questions