• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

No qualifying bean of type myBean is defined in Project

 
Bartender
Posts: 1815
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Issue below is resolved.

Added:

GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load("classpath:servlet.xml");
ctx.refresh();

to sample code and then myBean was found.

-------------------


Hello,

I'm getting a No Qualifying bean exception, but it seems that I have everything wired OK (well, maybe not?).

Here's my setup:

In the sample code where I'm trying to reference the bean and have defined the context, I do this:

AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
AppConfig.class);

.
.
.

Bean myBean = context.getBean(MyBean.class);
String userName = myBean.getUsername();

In the class, this compiles fine and resolves to the bean class created.

----

Then, in AppConfig.java, I have this definition:

@ImportResource("classpath:/servlet.xml")

where, the bean is defined like this:

<bean id="myBean" class="utils.MyBean" c:username="${jdbc.username}"/>

----

In the app.properties, I have:

jdbc.username=Hello JDBC

---

But, trying to run it fails with the "No qualifying bean of type myBean" exception when I try to "context.getBean(MyBean.class);" in the code above.

Would appreciate any ideas.

Thanks,

mike
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You marked this as resolved did you figure it out? Also my example was for a simple stand alone application. On a web application there are 2 contexts. The root context where your services, security, and property stuff should go and the servlet context where you controller mappings should go. If you are testing this in a web-application maybe you can show how you are loading your contexts. You will have problems like you described if you don't put the property source stuff in the root context.

I posted the code for the example we discussed, to a new github account. Just download the zip or clone the repo. Import it as an existing maven project into sts, right click application.java and run as java project.

https://github.com/wgorder/cr-property-sources
 
Mike London
Bartender
Posts: 1815
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bill Gorder wrote:You marked this as resolved did you figure it out? Also my example was for a simple stand alone application. On a web application there are 2 contexts. The root context where your services, security, and property stuff should go and the servlet context where you controller mappings should go. If you are testing this in a web-application maybe you can show how you are loading your contexts. You will have problems like you described if you don't put the property source stuff in the root context.

I posted the code for the example we discussed, to a new github account. Just download the zip or clone the repo. Import it as an existing maven project into sts, right click application.java and run as java project.

https://github.com/wgorder/cr-property-sources



Thanks very much.

Yes, by also including the code below, Spring found the xml bean definition.

GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load("classpath:servlet.xml");
ctx.refresh();

-----

I truly appreciate your superb help and insights.

THANK YOU!!!



mike
 
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic