• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to import beans annotated with @Bean from other project

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a situation where I need to import beans annotated with @Bean from one project to another project. Is there any way to achieve this.

For example I have project A and Project B, I want to use a bean of project A in project B so that I don't want to write the same code again. All these DAO beans are annotated with @Bean
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your XML, you can specify that you want that component scanned by specifying the package name:

 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raaja, you will have to provide more details. Are you using Spring Javabased Configuration?

If one project has a configuration like this


And you want to include this bean in your own project, you can do this




AConfig will have to be on classpath of project B.
 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Jeanne and Javesh.

Project A is having java configuration and project B is xml configured. As suggested by Jeanne I used <context:component-scan base-package="com.coderanch.myPackage" /> and imported project A's spring-context xml. But I dont have any idea what is happening when I run the test it is throwing following error as it is not able to find the bean.



project A config file



And individually project A is running

Test class

 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to access the service from project A in project B after adding the following line



along with



ref: http://stackoverflow.com/questions/8391944/getting-spring-error-bean-named-x-must-be-of-type-y-but-was-actually-of-ty

Thanks for the help Jeanne and Javesh.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic