gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:22:09 27 4
gpt4 key购买 nike

我正在 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)

我多次尝试解决这个错误,但都失败了。我该如何解决这个错误?我需要你的帮助。

这是我的 SqlMapConfig.xml、applicationContext 和我的根上下文。

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

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

和我的根上下文

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

最佳答案

配置就是配置,尝试去google一下。它看起来像下面这样

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

我认为,这就是构建失败的原因。

关于java - 错误: org. springframework.web.context.ContextLoader - 上下文初始化失败org.springframework.beans.factory.BeanCreationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32642310/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com