Results 1 to 1 of 1
Thread: Spring - property not autowired
- 09-07-2011, 01:31 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 1
- Rep Power
- 0
Spring - property not autowired
Hi
I'm new to annotaion based spring, so this might be a silly question, so please forgive me :(
I've got a vaadin portlet for liferay. The main class is IpinApplication. In IpinApplication is a MyBeanInterface property which I would like to autowire. Below are the code and application context file. I've tried various different context files, but I just can't get my myBeanInterface to be autowired to IpinApplication, although the myBeanInterface bean does get created (I debugged to establish this). No errors are getting logged to my appservers log files. Any help will be much appreciated.
IpinApplication.java:
MyBeanInterface.java:Java Code:package za.co.itemate.ipin; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Configurable; import org.springframework.beans.factory.annotation.Qualifier; import za.co.itemate.ipin.interfaces.MyBeanInterface; import com.vaadin.Application; import com.vaadin.ui.*; @Configurable(preConstruction = true) public class IpinApplication extends Application { private static final long serialVersionUID = 1L; private MyBeanInterface myBeanInterface; @Override public void init() { Window mainWindow = new Window("Ipin Application"); Label label = new Label("Hello Vaadin user: " + myBeanInterface); mainWindow.addComponent(label); setMainWindow(mainWindow); } public MyBeanInterface getMyBeanInterface() { return myBeanInterface; } @Autowired public void setMyBeanInterface(@Qualifier("myBeanInterface") MyBeanInterface myBeanInterface) { this.myBeanInterface = myBeanInterface; } }
Please help?Java Code:package za.co.itemate.ipin.interfaces; public interface MyBeanInterface { public String getName(); }
MyBeanInterfaceImpl.java:
applicationContext.xml:Java Code:package za.co.itemate.ipin; import za.co.itemate.ipin.interfaces.MyBeanInterface; public class MyBeanInterfaceImpl implements MyBeanInterface { public MyBeanInterfaceImpl() { System.out.println("Test"); } public String getName() { return "MyBeanInterfaceImpl"; } }
I've also tried to define IpinApplication as a bean, but this did not help either:Java Code:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans [url]http://www.springframework.org/schema/beans/spring-beans-3.1.xsd[/url] [url=http://www.springframework.org/schema/context]Index of /schema/context[/url] http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <!-- Turn on AspectJ @Configurable support --> <context:spring-configured /> <context:annotation-config /> <context:component-scan base-package="za.co.itemate.ipin" /> <!-- >Turn on @Autowired, @PostConstruct etc support --> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" /> <bean id="myBeanInterface" class="za.co.itemate.ipin.MyBeanInterfaceImpl"/> </beans>
Java Code:... <bean id="mainApp" class="za.co.itemate.ipin.IpinApplication"> <property name="myBeanInterface" ref="myBeanInterface" /> </bean> ...web.xml snippet:Java Code:... <bean id="mainApp" class="za.co.itemate.ipin.IpinApplication"/> ...
Java Code:... <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext.xml</param-value> </context-param> ... <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> ...
Similar Threads
-
possible overlapping jars in spring annotated mvc/spring security project
By savantics in forum Web FrameworksReplies: 1Last Post: 12-27-2010, 05:21 PM -
XML property
By Abder-Rahman in forum XMLReplies: 1Last Post: 09-27-2009, 07:10 PM -
Be Elite Join Property Elite , Property Realtor Needed , Career With Us -
By mindyyong in forum Jobs OfferedReplies: 0Last Post: 06-25-2009, 05:28 AM -
How to use compound property names in Spring
By Java Tip in forum Java TipReplies: 0Last Post: 03-30-2008, 10:08 AM -
How to use compound property names in Spring
By JavaBean in forum Java TipReplies: 0Last Post: 09-26-2007, 08:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks