K
K
Konstantin Malyarov2016-03-19 23:58:37
Java
Konstantin Malyarov, 2016-03-19 23:58:37

How to solve given exception in Spring?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  
  
  <bean id="PNV" class="ru.model.PNV">
    <constructor-arg ref="FamilyPNV" type="ru.datePNV.FamilyPNV"
      name="familypnv" index="1" />
    <constructor-arg ref="NamePNV" type="ru.datePNV.NamePNV"
      name="namepnv" index="2" />
    <constructor-arg ref="PatronymicPNV"
      type="ru.datePNV.PatronymicPNV" name="patronymicpnv" index="3" />
  </bean>
  <bean id="FamilyPNV" class="ru.datePNV.FamilyPNV"></bean>
  <bean id="NamePNV" class="ru.datePNV.NamePNV"></bean>
  <bean id="PatronymicPNV" class="ru.datePNV.PatronymicPNV"></bean>
</beans>

мар 19, 2016 11:49:37 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org[email protected]5511e6b9: startup date [Sat Mar 19 23:49:37 MSK 2016]; root of context hierarchy
мар 19, 2016 11:49:37 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [context.xml]
мар 19, 2016 11:49:38 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3e4eb331: defining beans [PNV,FamilyPNV,NamePNV,PatronymicPNV]; root of factory hierarchy
мар 19, 2016 11:49:38 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.s[email protected]3e4eb331: defining beans [PNV,FamilyPNV,NamePNV,PatronymicPNV]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PNV' defined in class path resource [context.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
  at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1045)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:949)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
  at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
  at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
  at ru.main.Start.main(Start.java:10)

What am I doing wrong? name and index set to boom.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Malyarov, 2016-03-20
@Konstantin18ko

Found the problem! context.xml should be in a folder labeled as resource ! And not just in a regular folder.

A
angry_cellophane, 2016-03-20
@angry_cellophane

Check that the PNV constructor takes the three parameters in the given order, i.e. it looks like:

public PNV(FamilyPNV familypnv, NamePNV namepnv, PatronymicPNV patronymicpnv)

G
goshan_p, 2016-03-20
@goshan_p

Learn to read the error trace. Here is everything:

Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question