java - Spring 3.2.9;瓷砖2.0.7;调用init方法失败;嵌套异常是 java.lang.IllegalArgumentException : No DataSource specified

标签 java spring spring-mvc spring-webflow-2

我正在尝试将 Spring 项目从 2.5.6 更新到 3.2.9。我们使用 Tiles 2.0.7 和 Spring Web Flow 2.3。我遇到了一个错误,该错误在 Stack Overflow 或其他论坛中没有相关解决方案: (部分堆栈跟踪):

####<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 ) );
        }
    }
}

最佳答案

LkTimezonesDAO

JdbcTemplate jcTemplate = new JdbcTemplate();

您正在使用 new 关键字自己实例化 jdbcTemplate,它如何知道 dataSource

您应该通过 @Autowiredxml 注入(inject)上下文中定义的内容。

关于java - Spring 3.2.9;瓷砖2.0.7;调用init方法失败;嵌套异常是 java.lang.IllegalArgumentException : No DataSource specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29654929/

相关文章:

java - Spring Boot 查询未更新 mysql 数据库

java - @Service 中带有 Kotlin 的 Spring Boot @Autowired 始终为空

java - 我正在尝试根据图表值获取图表网页。但

java - JButton() 仅在鼠标悬停时起作用

java - ASM COMPUTE_FRAMES If + 赋值错误

java - 外行术语中的 Spring 传播示例

java - spring boot中为静态资源设置setCachePeriod

java - java中通过链接发送json格式

java - 将 ArrayList 添加到另一个 ArrayList 中

Java FX MVC 多个 View