Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » @PostConstruct method is not invoked
@PostConstruct method is not invoked [message #634771] Sat, 23 October 2010 10:37 Go to next message
Kostas Kougios is currently offline Kostas KougiosFriend
Messages: 42
Registered: August 2010
Member
I am scratching my head over this since yesterday. I have a bean with the @PostConstruct annotation in a method, but it is not invoked:

public class DerbyManager implements IDerbyManager
{
	private final Logger	logger	= LoggerFactory.getLogger(getClass());
	@PostConstruct
	protected void init()
	{
		logger.info("initializing");

		loadEmbeddedDriver();
	}
....


my module-context.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"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
	">
	<context:annotation-config/>
	<bean id="derbyManager" class="com.rits.derby.impl.DerbyManager"/>
</beans>


The bean itself is initialized (if I add logging at the constructor, I see it in the log).

my manifest.mf:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Derby Manager
Bundle-SymbolicName: com.rits.derby
Bundle-Version: 1.0.0
Bundle-Vendor: RITS
Import-Library: org.springframework.spring
Import-Bundle: org.apache.commons.dbcp
 ,derbyclient
 ,com.rits.databases
Import-Package: org.slf4j
Export-Package: com.rits.derby


I used to have the same issue in the past and was resolved by Import-Library: org.springframework.spring . Any ideas?

I've uploaded the bundle.

Thanks
Re: @PostConstruct method is not invoked [message #635189 is a reply to message #634771] Mon, 25 October 2010 22:16 Go to previous messageGo to next message
Kostas Kougios is currently offline Kostas KougiosFriend
Messages: 42
Registered: August 2010
Member
I am using springframework 3.0.4. How does virgo uses spring/module-context.xml? Does it loads it with the embedded spring v3.0.0?
Re: @PostConstruct method is not invoked [message #635204 is a reply to message #634771] Tue, 26 October 2010 00:25 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
Try to import

Import-Package: javax.annotation

It is just very possible that annotation is not visible because it is not imported and spring container just skips it.
Re: @PostConstruct method is not invoked [message #635457 is a reply to message #635204] Tue, 26 October 2010 21:33 Go to previous messageGo to next message
Kostas Kougios is currently offline Kostas KougiosFriend
Messages: 42
Registered: August 2010
Member
thanks, that did the trick.

So what was the issue? The annotation could not be found by spring because it wasn't in the bundle's classpath? But why weren't there any class not found exceptions?

Re: @PostConstruct method is not invoked [message #635673 is a reply to message #635457] Wed, 27 October 2010 17:15 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
The difference is defensive coding. Lots of it Smile

Example from org.springframework.context.annotation.AnnotationConfigUtils .this class is ultimately responsible for registering BeanFactoryPostProcessors
	private static final boolean jsr250Present =
			ClassUtils.isPresent("javax.annotation.Resource", AnnotationConfigUtils.class.getClassLoader());

// and later 
...
// Check for JSR-250 support, and if present add the CommonAnnotationBeanPostProcessor.
		if (jsr250Present && !registry.containsBeanDefinition(COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class);
			def.setSource(source);
			beanDefs.add(registerPostProcessor(registry, def, COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
		}

Re: @PostConstruct method is not invoked [message #635731 is a reply to message #635673] Wed, 27 October 2010 21:22 Go to previous message
Kostas Kougios is currently offline Kostas KougiosFriend
Messages: 42
Registered: August 2010
Member
that's lots of code though.

I suspect equinox is not jdk5 compatible and didn't throw classnotfound exception due to the missing package import...
Previous Topic:deploying simple war file causes IllegalArgumentException: Required 'bundleContext' property was not
Next Topic:dm Server Tools manifest problem
Goto Forum:
  


Current Time: Fri Mar 29 15:50:02 GMT 2024

Powered by FUDForum. Page generated in 0.07566 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top