O
O
Oleg Mikhailov2018-07-11 17:46:59
Java
Oleg Mikhailov, 2018-07-11 17:46:59

How to fix dataSource/jdbcTemplate error on Spring boot?

When starting the app, it throws an error, although everything is specified in config.xml
I already spent a whole day on this, but I can’t understand why it doesn’t pull them
Crashes on the run () method

@SpringBootApplication
public class DeliverySpringApplication {

  public static void main(String[] args) {
    SpringApplication.run(DeliverySpringApplication.class, args);
  }
}

config.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:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://test-db.host:5432/test"/>
    <property name="username" value="user"/>
    <property name="password" value="JKN7sa84gsufi"/>
  </bean>

  <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource"></property>
  </bean>

  <bean id="daoImpl" class="com.delivery_spring.delivery.dao.promo.PromoDaoImpl">
    <property name="jdbcTemplate" ref="jdbcTemplate"></property>
  </bean>
  <bean id="cityDao" class="com.delivery_spring.delivery.dao.city.CityDaoImpl">
    <property name="jdbcTemplate" ref="jdbcTemplate"></property>
  </bean>

</beans>

mistake

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'promoDaoImpl' defined in file [/home/oleg/workProject/delivery_spring/out/production/classes/com/mobsterdeliveryv2/delivery_spring/delivery/dao/promo/PromoDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
Caused by: java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
at org.springframework.jdbc.core.support.JdbcDaoSupport.checkDaoConfig(JdbcDaoSupport.java:116) ~[spring-jdbc-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1767) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1704) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Eremin, 2018-07-11
@EreminD

<property name="url" value="jdbc:postgresql://mobster-db.host:5432/еуые"/>

wow - is it supposed to be like that?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question