Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Spring
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Liutauras Vilda
Paul Clapham
Sheriffs:
paul wheaton
Tim Cooke
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Piet Souris
Bartenders:
Mike London
Forum:
Spring
Property 'sql' is required
pramod talekar
Ranch Hand
Posts: 367
I like...
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi All,
Could you please advise on the below error :
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactDaos' defined in class path resource [META-INF/spring/app-context-xml.xml]: Invocation of init method failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Property 'sql' is required 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:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at com.apress.ch8.xml.test.SelectAllContactsTest.main(SelectAllContactsTest.java:17) Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Property 'sql' is required at org.springframework.jdbc.object.RdbmsOperation.compile(RdbmsOperation.java:329) at org.springframework.jdbc.object.RdbmsOperation.afterPropertiesSet(RdbmsOperation.java:317) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) ... 10 more
<bean id="contactDaos" class="com.apress.ch8.xml.SelectAllContacts"> <property name="dataSource" ref="dataSource"></property> <!-- <constructor-arg type="DataSource" ref="dataSource"></constructor-arg> --> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="url" value="jdbc:mysql://localhost:3306/TEST"></property> <property name="username" value="root"></property> <property name="password" value="admin"></property> <!-- <property name="initialSize" value="5" /> <property name="maxActive" value="10" /> --> </bean>
Below is the main class.
package com.apress.ch8.xml; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import javax.sql.DataSource; import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.object.MappingSqlQuery; public class SelectAllContacts extends MappingSqlQuery<Contact> implements ContactDao { private DataSource dataSource; SelectAllContacts selectAllContacts; private static final String SQL_SELECT_ALL_CONTACT = "select id, first_name, last_name,birth_date from contact"; public SelectAllContacts() { // TODO Auto-generated constructor stub } public SelectAllContacts(DataSource dataSource) { super(dataSource, SQL_SELECT_ALL_CONTACT); } @Override protected Contact mapRow(ResultSet rs, int rowNum) throws SQLException { Contact contact = new Contact(); contact.setId(rs.getLong("id")); contact.setFirstName(rs.getString("first_name")); contact.setLastName(rs.getString("last_name")); contact.setBirthDate(rs.getDate("birth_date")); return contact; } public List<Contact> findAll() throws SQLException { selectAllContacts = new SelectAllContacts(dataSource); return selectAllContacts.execute(); } public DataSource getDataSource() { return dataSource; } public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; //selectAllContacts = new SelectAllContacts(dataSource); } }
Below is the
test
class.
package com.apress.ch8.xml.test; import java.sql.SQLException; import java.util.List; import org.springframework.context.support.GenericXmlApplicationContext; import com.apress.ch8.xml.Contact; import com.apress.ch8.xml.ContactDao; public class SelectAllContactsTest { public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("classpath:META-INF/spring/app-context-xml.xml"); ctx.refresh(); ContactDao ContactDao = ctx.getBean("contactDaos", ContactDao.class); try { List<Contact> contacts = ContactDao.findAll(); listContacts(contacts); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static void listContacts(List<Contact> contacts){ for (Contact contact : contacts) { System.out.println(contact); } } }
The datasource configuration is valid.
Also
//selectAllContacts = new SelectAllContacts(dataSource);
should this be called in the setter method itself or in the findAll() method?
Please advise.
Thanks,
Pramod
pramod talekar
Ranch Hand
Posts: 367
I like...
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Also, if I change the setter method to this
public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; selectAllContacts = new SelectAllContacts(dataSource); }
and remove it from findAll() , I get below error :
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactDaos' defined in class path resource [META-INF/spring/app-context-xml.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.StackOverflowError at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 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:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at com.apress.ch8.xml.test.SelectAllContactsTest.main(SelectAllContactsTest.java:17) Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.StackOverflowError at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393) ... 11 more
Thanks,
Pramod
vaijesh basavarajappa
Greenhorn
Posts: 5
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I guess you missed out driverClassName property while configuring datasource.
Vaijesh
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Example for JMS sender - receiver
Problem in using multiaction controller in spring
spring 2.5.3 / hibernate 3 sessionFactory NullPointerException
What's wrong with my spring config?
QuerySyntaxException (table is not mapped)
More...