Page 1 of 1

Some Beans are null

Posted: Fri Feb 18, 2011 11:49 am
by idont
Hi,

As you recall I am new to spring, but I read up on it quite a bit, and I do like the idea, I finally figured out how to integrate it with my framework (Wicket, I need to use a different type of annotation (SpringBean)) - not too difficult in the end. And I have no more errors using BroadLeaf except....

this like other services report to be be null:
@SpringBean(name="blCustomerService")
private CustomerService customerService;

Now, I should note that the following is not null as I understand:
@SpringBean(name="blPersistenceUnitManager")
private MergePersistenceUnitManager mpum;

Besides having all the jars I also have the following files:
applicationContext.xml (in WEB-INF) (and a properties file for the sql data).
persistence-container.xml (in META-INF)

I can copy the files here but they are similar to the examples.


Now I have been looking through the demos etc... but there are quite a few xml files and I am not sure which I need and which I don't.... I am not sure if I am missing something glaring like a file or something is simply not working in the code. Btw, I am using Glassfish if that is an issue.

I appreciate anyone trying to make heads or tails of this....
Matthew

Re: Some Beans are null

Posted: Sat Feb 26, 2011 3:05 pm
by jefffischer
blCustomerService is declared via annotations in the class CustomerServiceImpl in the broadleaf-profile.jar. If you're getting null for this service in your spring managed bean, then I suspect one of two things. Either you don't have the broadleaf-profile.jar on the classpath (but I imagine you do or otherwise you would get a compilation error for your class that references CustomerService), or you have not engaged the Spring scanning mechanism. For Spring to autowire these annotated services, you have to include some key items in your application context xml file to get it started. In the broadleaf application context, we accomplish this via the following:

Code: Select all

<context:component-scan base-package="org.broadleafcommerce" />


Refer to the Spring documentation around the topic of autowiring for more information.