简体   繁体   English

java.lang.IllegalArgumentException:启动tomcat时需要'dataSource'或'jdbcTemplate'

[英]java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required when starting tomcat

Coming up with an issue in regards to spring and tomcat.提出有关 spring 和 tomcat 的问题。 I have the following code我有以下代码

BookDAOImpl.java BookDAOImpl.java

@Repository
public class BookDAOImpl extends NamedParameterJdbcDaoSupport implements BookDAO {

    private class BookMapper implements RowMapper<Book> {

        @Override
        public Book mapRow(ResultSet resultSet, int rowNum) throws SQLException {
            Book book = new Book();
            book.setId(resultSet.getInt("id"));
            book.setTitle(resultSet.getString("title"));
            book.setAuthor(resultSet.getString("author"));
            book.setPublisher(resultSet.getString("publisher"));
            book.setPublicationDate(resultSet.getDate("publication_date"));
            book.setIsbn(resultSet.getString("isbn"));
            book.setAvailable(resultSet.getBoolean("available"));
            return book;
        }

    }
}

LibraryDataSource.java库数据源.java

@Component("dataSource")
public class LibraryDataSource extends DriverManagerDataSource {

    @Autowired
    public LibraryDataSource(@Value("${url}")String url, @Value("${user}")String username, @Value("${password}")String password) {
        super(url, username, password);
    }
}

application-context.xml应用程序上下文.xml

<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:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd" 
    default-autowire="byName">

    <context:annotation-config/>
    <context:component-scan base-package="com.LibraryManagement.*" />
    <context:property-placeholder location="classpath:prop.properties"/>
</beans>

Now as far as i know the autowiring should pick up the dataSource and autowire it to the Repository but when i start tomcat i get the following error现在据我所知,自动装配应该拾取数据源并将其自动装配到存储库,但是当我启动 tomcat 时,我收到以下错误

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookDAOImpl' defined in file [P:\SourceControl\EclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\WebLibraryManagemenet\WEB-INF\classes\com\LibraryManagement\access\impl\BookDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)

Any idea whats going on?知道发生了什么吗?

Thanks谢谢

Add the following constructor to BookDAOImpl :将以下构造函数添加到BookDAOImpl

@Autowired 
public BookDAOImpl(DataSource dataSource) {
    setDataSource(dataSource);
}

暂无
暂无

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

相关问题 java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required - java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required Spring Framework IllegalArgumentException&#39;dataSource&#39;或&#39;jdbcTemplate&#39;是必需的JAVA - Spring Framework IllegalArgumentException 'dataSource' or 'jdbcTemplate' is required JAVA IllegalArgumentException:扩展JdbcUserDetailsManager时需要'dataSource'或'jdbcTemplate' - IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required when extending JdbcUserDetailsManager java.lang.IllegalArgumentException:需要contentIntent - java.lang.IllegalArgumentException: contentIntent required java.lang.IllegalArgumentException:属性&#39;transactionManager&#39;是必需的 - java.lang.IllegalArgumentException: Property 'transactionManager' is required java.lang.IllegalArgumentException - java.lang.IllegalArgumentException java.lang.IllegalArgumentException - java.lang.IllegalArgumentException java.lang.IllegalArgumentException:未指定Junit和Mockito的数据源 - java.lang.IllegalArgumentException: No DataSource specified Junit and Mockito 使用@Autowired时java.lang.IllegalArgumentException - java.lang.IllegalArgumentException when use @Autowired 启动 Jenkins 服务时出现 Java 异常“java.lang.IllegalArgumentException: Expecting ----prefix” - Java Exception "java.lang.IllegalArgumentException: Expecting ----prefix" when starting Jenkins Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM