0

I have a service that I am trying to autowire in my controller. Every time I build the application I get this error. I know I'm doing something wrong in my application context. Can anyone shed some light?

This is my project on git: https://github.com/zackh321/spring-swag

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

  <bean id="triangleService" class="com.zmags.interview.service.triangle.TriangleService" abstract="true">
    <property name="triangleController" ref="triangleController"></property>
  </bean>


</beans>

Error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoController' defined in file [/Users/zhyder/Desktop/springboot-swagger-test/spring-swag/target/classes/com/zmags/interview/controller/DemoController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zmags.interview.controller.DemoController]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanIsAbstractException: Error creating bean with name 'triangleService': Bean definition is abstract

EDIT appContext

<?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-3.0.xsd">

  <bean id="demoController" class="com.zmags.interview.controller.DemoController">
    <property name="triangleService" ref="triangleService"></property>
  </bean>

</beans>
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Zack
  • 5,108
  • 4
  • 27
  • 39
  • 2
    What do you think `Error creating bean with name 'triangleService': Bean definition is abstract` means? – Sotirios Delimanolis Sep 06 '17 at 21:02
  • @SotiriosDelimanolis It's saying that my Service interface is abstract right? – Zack Sep 06 '17 at 21:06
  • I see that you are trying to autowire ` @Autowired TriangleService triangleService; ` , Try to auto wire the implementation instead `TriangleServiceImpl` – Arar Sep 06 '17 at 21:07
  • 1
    It's saying _Bean definition is abstract_. – Sotirios Delimanolis Sep 06 '17 at 21:08
  • https://stackoverflow.com/questions/19094782/spring-throws-the-error-bean-definition-is-abstract – Sotirios Delimanolis Sep 06 '17 at 21:09
  • https://stackoverflow.com/questions/9397532/what-is-meant-by-abstract-true-in-spring – Sotirios Delimanolis Sep 06 '17 at 21:09
  • Your github code is using spring boot, then why are you using xml configuration? If you are using XML then your triangle service bean definition should be interface is not required to be declared in the bean configuration – Amit K Bist Sep 06 '17 at 21:18
  • @SotiriosDelimanolis I updated the appContext above. Still not quite understanding what you are saying. When I run the app, it still complains about it needing a bean for triangleService – Zack Sep 06 '17 at 21:18
  • Everything should already be explained in those two links I shared (I will vote to close as duplicate once the day rolls over). If you still don't understand, ask yourself: what does _`abstract="true"`_ mean and do? – Sotirios Delimanolis Sep 06 '17 at 21:19
  • The Impl needs to be autowired, not the service, correct? – Zack Sep 06 '17 at 21:21
  • [_First of all abstract bean has nothing to do with the abstract class they don't even need to be mapped to a class.They are used to group the common properties shared by another beans.But you can not use an abstract bean as a ref to wire a property in another bean._](https://stackoverflow.com/a/19098046/438154) – Sotirios Delimanolis Sep 06 '17 at 21:23
  • @SotiriosDelimanolis I'm sorry, I don't understand that example when I compare the context to mine. Something is going over my head. – Zack Sep 06 '17 at 21:26
  • Ok, forget ALL of that. Why did you add `abstract="true"` to your bean definition in the XML? – Sotirios Delimanolis Sep 06 '17 at 21:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/153814/discussion-between-zack-and-sotirios-delimanolis). – Zack Sep 06 '17 at 21:29

0 Answers0