我试图将我们的Spring项目从2.5.6更新到3.2.9。我们正在使用Tiles 2.0.7和Spring Web Flow 2.3。我坚持在Stack Overflow或其他论坛中没有相关解决方案的错误: (部分Stacktrace):
####<Apr 13, 2015 4:11:53 PM GMT-06:00> <Warning> <HTTP> <xxxxxxxxxx.xxx.xxx.xxx.com> <managedserver1> <[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1428963113472> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lkTimeZones' defined in ServletContext resource [/WEB-INF/webObjectBeans.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No DataSource specified. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lkTimeZones' defined in ServletContext resource [/WEB-INF/webObjectBeans.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No DataSource specified at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
我的applicationContext.vxml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
<bean name="jndiName" class="java.lang.String">
<constructor-arg value="wevsplatds"/>
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiEnvironment">
<props>
<prop key="java.naming.factory.initial">
weblogic.jndi.WLInitialContextFactory
</prop>
</props>
</property>
<property name="jndiName" ref="jndiName"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg><ref bean="dataSource"/></constructor-arg>
</bean>
这是我的webObjectBeans.xml文件的摘录:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<!-- Formatting Beans -->
<bean name="loc" class="java.util.Locale">
<constructor-arg index="0" type="java.lang.String"
value="${languageId}"/>
<constructor-arg index="1" type="java.lang.String"
value="${countryId}"/>
</bean>
<bean name="dateFormatSymbols" class="java.text.DateFormatSymbols">
<constructor-arg type="java.util.Locale" ref="loc"/>
</bean>
<bean name="calendarTagDateFormat" class="java.text.SimpleDateFormat">
<constructor-arg value="MM-dd-yyyy"/>
</bean>
<bean name="monthlyLinksDateFormat" class="java.text.SimpleDateFormat">
<constructor-arg value="MMMM yyyy"/>
</bean>
<bean name="weeklyLinksDateFormat" class="java.text.SimpleDateFormat">
<constructor-arg value="MMM d"/>
</bean>
<!-- System Beans -->
<bean id="cmAlarms"
class="com.fruit.apples.alarm.Alarm"
p:errorCode="CALLMGRWEB001"/>
<!-- Collections Beans -->
<bean id="lkTimeZones" class="com.fruit.apples.customer.webdisplay.collections.LkTimeZones"
init-method="loadActiveTimeZones"
p:timeZonesDao-ref="lkTimeZonesDAO" />
<bean id="lkHelps"
class="com.fruit.apples.customer.webdisplay.collections.LkHelps"
init-method="loadActiveHelp"
p:lkHelpDao-ref="lkHelpDAO" />
<bean id="lkActivityAreas"
class="com.fruit.apples.customer.webdisplay.collections.LkActivityAreas"
init-method="loadActiveActivityArea"
p:lkActivityAreaDAO-ref="lkActivityAreaDAO" />
最后来自LkTimezonesDAO.java的一节:
package com.fruit.apples.customer.dao;
import com.fruit.apples.customer.webdisplay.LkTimeZone;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.dao.EmptyResultDataAccessException;
public class LkTimezonesDAO extends CustomerWebDaoImpl
{
private static final long serialVersionUID = 2367566965661648309L;
/**
* getAllLkTimeZones retrieves all data for LkTimeZoneObjects. The data
* populates the List Object passed to this method with LkTimeZone objects
* as appropriate for the data retrieved
*
* @param listToLoad the List Object to be populated
*/
public void getAllLkTimeZones( List<LkTimeZone> listToLoad )
{
listToLoad.clear();
JdbcTemplate jcTemplate = new JdbcTemplate();
List<Map<String, Object>> rows = jcTemplate.queryForList(queries.get( "allLkTimezonesQuery" ) );
if ( (rows!=null) || (0 < rows.size() ) )
{
for ( Map<String,Object> row : rows )
{
listToLoad.add( initializeLkTimeZone( row ) );
}
}
}
/**
* getAllLkTimeZones retrieves only active data for LkTimeZoneObjects. The
* data populates the List Object passed to this method with LkTimeZone
* objects as appropriate for the data retrieved
*
* @param listToLoad the List Object to be populated
*/
public void getActiveLkTimeZones( List<LkTimeZone> listToLoad )
{
listToLoad.clear();
JdbcTemplate jcTemplate = new JdbcTemplate();
List<Map<String, Object>> rows = jcTemplate.queryForList(queries.get( "activeLkTimezonesQuery" ) );
if ( ( rows != null ) || ( 0 < rows.size() ) )
{
for ( Map<String,Object> row : rows )
{
listToLoad.add( initializeLkTimeZone( row ) );
}
}
}
答案 0 :(得分:0)
在LkTimezonesDAO
JdbcTemplate jcTemplate = new JdbcTemplate();
您使用jdbcTemplate
关键字自己实例化new
,它如何了解dataSource
?
您应该通过@Autowired
或xml
注入上下文中定义的那个。
答案 1 :(得分:0)
好的,我将dataSource
注入了DAO文件,但又出现了'NullPointerException'错误。不幸的是,我认为部分问题在于我有14个不同的DAO文件将各种查询连接到数据库。我通过@Autowire
连接到LkTimezonesDAO.java的一个实例如下:
`import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
/**
* ClmgrLkTimezonesTableDAO is a data access object specifically designed to
* retrieve and set LkTimeZone object data.
*
*/
@Service("timeZonesService")
@Repository
public class LkTimezonesDAO extends CustomerWebDaoImpl
{
private static final long serialVersionUID = 2367566965661648309L;
private JdbcTemplate jdbcTemplate ;
@Autowired
public void init(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
``
这是一个示例堆栈跟踪:
`####<Apr 21, 2015 11:50:30 AM GMT-06:00> <Warning> <HTTP> <xxxxxxxx.xx.xxx.xxx.com> <managedserver1>
<[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1429638630468>
<BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lkTimeZones' defined in ServletContext resource
[/WEB-INF/webObjectBeans.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lkTimeZones' defined in ServletContext resource
[/WEB-INF/webObjectBeans.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:376)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)