简体   繁体   English

错误:org.springframework.web.context.ContextLoader-上下文初始化失败org.springframework.beans.factory.BeanCreationException

[英]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 我正在tomcat 7中开发网站(spring 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) 

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. 这是我的SqlMapConfig.xml,applicationContext和我的根上下文。

my SqlMapConfig.xml(config/SqlMapConfig.xml) 我的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) 我的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> 

Configuration is configuration, try to find it out from google. 配置是配置,请尝试从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 并再次检查您的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>

I think, that's why fail to build. 我认为,这就是为什么无法建立。

As jamesBlake rightly mentioned, configuration file is configuration. 正如jamesBlake正确提到的那样,配置文件就是配置。 You are providing the mapper file as configuration and ibatis cannot parse it as configuration. 您正在将映射器文件作为配置提供,ibatis无法将其解析为配置。

Configuration is file where you define your ibatis settings and alias (if any) which can be used in mapper files 配置文件是您定义ibatis设置和别名(如果有)的文件,可在映射器文件中使用

Mapper file is one where you actually write your queries.You can have as many mapper files as you want. 映射器文件是您实际编写查询的位置。您可以根据需要拥有任意数量的映射器文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:org.springframework.web.context.ContextLoader - 上下文初始化失败 - ERROR: org.springframework.web.context.ContextLoader - Context initialization failed 错误org.springframework.web.servlet.DispatcherServlet-上下文初始化失败org.springframework.beans.factory.BeanCreationException:错误 - ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error Spring MVC + Hibernate Context初始化失败org.springframework.beans.factory.BeanCreationException:创建bean时出错 - Spring mvc + hibernate Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean Spring错误-上下文初始化失败:org.springframework.beans.factory.BeanCreationException - Spring ERROR - Context initialization failed: org.springframework.beans.factory.BeanCreationException 错误:org.springframework.web.context.ContextLoader-上下文初始化失败[context-security.xml] - ERROR: org.springframework.web.context.ContextLoader - Context initialization failed [context-security.xml] 春季错误:org.springframework.web.context.ContextLoader-上下文初始化失败 - spring error :org.springframework.web.context.ContextLoader - Context initialization failed 码头:错误[org.springframework.web.context.ContextLoader:215]-上下文初始化失败 - Jetty: ERROR [org.springframework.web.context.ContextLoader:215] - Context initialization failed 上下文初始化失败org.springframework.beans.factory.BeanCreationException:使用类路径资源中定义的名称创建bean时出错 - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name defined in class path resource org.springframework.beans.factory.BeanCreationException错误 - Error with org.springframework.beans.factory.BeanCreationException [ERROR] org.springframework.beans.factory.BeanCreationException - [ERROR]org.springframework.beans.factory.BeanCreationException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM