Closed alltomsport closed 9 years ago
Did you annotate your view with @Configurable and compile your code through the aspectj compiler? Things like ApplicationConfig are injected using compile-time weaving and if you didn't weave the aspects this is an error you could get. But it's hard to find out without seeing the code.
Thanks for the quick response!
No, I have neither used the annotation or the aspectj compiler, so that seems like a possible solution. In the sample app I refered to, there is no @Configurable annotation on the views though, how come?
Have to do dome reading on the aspectj compiler, but I guess I need a plugin for Eclipse and to included the aspectj-jar in my project?
Install Spring STS. It has all the tools you need build in.
http://spring.io/tools/sts/all
Or see https://github.com/cmadsen/Valkyrie-RCP/issues/9 for instructions.
Thanks! Have gotten all samples apps running and are now tryning to annotate my own application. Having some trouble might have more questions if I get stuck again!
Hi again! I have a lot of tables in my application which are instansiated with the new operator, this however leads to that fields in the superclass AbstractObjectTable that are marked @Autowired is not set, which leads to NPE:s in the init code in AbstractObjectTable where for example applicationConfig is referenced. Am I supposed to create all tables as beans in a @Configuration class now?
It is @Configurable not @Configuration you should use.
Yes sorry, typo.. But is the only way to getfor exmpale applicationConfig injected to AbstractObjectTable to create my sub class table as a bean?
I'm afraid it is. The reason why is because Valkyrie no longer relies on the static servicelocator pattern in order to get application service level beans such as the ApplicationConfig. So anytime you're injecting a bean into one of your own classes you need to use compile-time weaving in order to get it to work correctly. But normally, when using the jars, they should already be weaved and subclassing should work if you're not trying to autowire services into your own classes.
On Fri, Jan 10, 2014 at 12:46 PM, alltomsport notifications@github.comwrote:
Yes sorry, typo.. But is the only way to getfor exmpale applicationConfig injected to AbstractObjectTable to create my sub class table as a bean?
— Reply to this email directly or view it on GitHubhttps://github.com/cmadsen/Valkyrie-RCP/issues/15#issuecomment-32021306 .
Thanks, I understand, strange though that the sub classing doesn't work.. I use the jars from http://mvnrepository.com/artifact/dk.navicon/valkyrie-rcp-core/1.2 an its dependencies and runs it in a maven project in STS 3.4.0
Hi again! Seems like there is a problem?! with the weaving of the class files in the valkyrie jar. Could there be sometinh I missed?? Too get to the root of this problem I simply created a bean in the ApplicationConfig class:
@Configuration public class ApplicationConfig extends AbstractApplicationConfig { ... @Bean public CoinsLogTable coinsLogTable() { String[] columnNames = new String[]{"startDate", "endDate", "name", "status"}; CoinsLogTable table = new CoinsLogTable("CoinsLog", columnNames); return table; } ... }
@Configurable
public class CoinsLogTable extends AbstractObjectTable {
public CoinsLogTable(String modelId, String[] columnPropertyNames) {
super(modelId, columnPropertyNames);
}
...
}
but I still get the same NPE on applicationConfig when the bean coinsLogTable is created (strange when the weaving of applicationConfig works in for example the view-classes):
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'coinsLogTable' defined in class path resource [se/fgirot/client/ApplicationConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public se.fgirot.client.coinslog.CoinsLogTable se.fgirot.client.ApplicationConfig.coinsLogTable()] threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1029)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:925)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.valkyriercp.application.support.ApplicationLauncher.loadRootApplicationContext(ApplicationLauncher.java:215)
at org.valkyriercp.application.support.ApplicationLauncher.
Have you tried @Configurable(preConstruction=true)? Seems like it's using injected services in the constructor, in which case you need to add that argument.
On Tue, Jan 14, 2014 at 9:54 AM, alltomsport notifications@github.comwrote:
Hi again! Seems like there is a problem?! with the weaving of the class files in the valkyrie jar. Could there be sometinh I missed?? Too get to the root of this problem I simply created a bean in the ApplicationConfig class:
@Configuration https://github.com/Configuration public class ApplicationConfig extends AbstractApplicationConfig { ... @Bean https://github.com/Bean public CoinsLogTable coinsLogTable() { String[] columnNames = new String[]{"startDate", "endDate", "name", "status"}; CoinsLogTable table = new CoinsLogTable("CoinsLog", columnNames); return table; } ... }
@Configurable public class CoinsLogTable extends AbstractObjectTable {
public CoinsLogTable(String modelId, String[] columnPropertyNames) { super(modelId, columnPropertyNames); } ... }
but I still get the same NPE on applicationConfig when the bean coinsLogTable is created (strange when the weaving of applicationConfig works in for example the view-classes):
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'coinsLogTable' defined in class path resource [se/fgirot/client/ApplicationConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public se.fgirot.client.coinslog.CoinsLogTable se.fgirot.client.ApplicationConfig.coinsLogTable()] threw exception; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1029) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:925) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.valkyriercp.application.support.ApplicationLauncher.loadRootApplicationContext(ApplicationLauncher.java:215) at org.valkyriercp.application.support.ApplicationLauncher.(ApplicationLauncher.java:129) at org.valkyriercp.application.support.ApplicationLauncher.(ApplicationLauncher.java:83) at se.fgirot.client.Main.main(Main.java:24) Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public se.fgirot.client.coinslog.CoinsLogTable se.fgirot.client.ApplicationConfig.coinsLogTable()] threw exception; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:181) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570) ... 15 more Caused by: java.lang.NullPointerException at org.valkyriercp.table.support.AbstractObjectTable.init(AbstractObjectTable.java:350) at org.valkyriercp.table.support.AbstractObjectTable.(AbstractObjectTable.java:155) .
— Reply to this email directly or view it on GitHubhttps://github.com/cmadsen/Valkyrie-RCP/issues/15#issuecomment-32247849 .
Ah, that's a bug indeed. AbstractObjectTable uses the applicationConfig in its constructor (the init() method) and the @Configurable is without the preConstruction parameter, which causes the NPE. The annotation I suggested should solve the issue, but it needs looking at.
Thanks for the report.
On Tue, Jan 14, 2014 at 9:56 AM, Lieven Doclo lievendoclo1983@gmail.comwrote:
Have you tried @Configurable(preConstruction=true)? Seems like it's using injected services in the constructor, in which case you need to add that argument.
On Tue, Jan 14, 2014 at 9:54 AM, alltomsport notifications@github.comwrote:
Hi again! Seems like there is a problem?! with the weaving of the class files in the valkyrie jar. Could there be sometinh I missed?? Too get to the root of this problem I simply created a bean in the ApplicationConfig class:
@Configuration https://github.com/Configuration public class ApplicationConfig extends AbstractApplicationConfig { ... @Bean https://github.com/Bean public CoinsLogTable coinsLogTable() { String[] columnNames = new String[]{"startDate", "endDate", "name", "status"}; CoinsLogTable table = new CoinsLogTable("CoinsLog", columnNames); return table; } ... }
@Configurable public class CoinsLogTable extends AbstractObjectTable {
public CoinsLogTable(String modelId, String[] columnPropertyNames) { super(modelId, columnPropertyNames); } ... }
but I still get the same NPE on applicationConfig when the bean coinsLogTable is created (strange when the weaving of applicationConfig works in for example the view-classes):
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'coinsLogTable' defined in class path resource [se/fgirot/client/ApplicationConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public se.fgirot.client.coinslog.CoinsLogTable se.fgirot.client.ApplicationConfig.coinsLogTable()] threw exception; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1029) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:925) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.valkyriercp.application.support.ApplicationLauncher.loadRootApplicationContext(ApplicationLauncher.java:215) at org.valkyriercp.application.support.ApplicationLauncher.(ApplicationLauncher.java:129) at org.valkyriercp.application.support.ApplicationLauncher.(ApplicationLauncher.java:83) at se.fgirot.client.Main.main(Main.java:24) Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public se.fgirot.client.coinslog.CoinsLogTable se.fgirot.client.ApplicationConfig.coinsLogTable()] threw exception; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:181) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570) ... 15 more Caused by: java.lang.NullPointerException at org.valkyriercp.table.support.AbstractObjectTable.init(AbstractObjectTable.java:350) at org.valkyriercp.table.support.AbstractObjectTable.(AbstractObjectTable.java:155) .
— Reply to this email directly or view it on GitHubhttps://github.com/cmadsen/Valkyrie-RCP/issues/15#issuecomment-32247849 .
Thanks! That did the trick, got my first view working without errors!
With @Configurable(preConstruction=true) I can instansiate my table class with the new operator, without using the @Bean annotation.
Hi!
Was really happy when I discovered that there was as Spring 3.X version och Spring Richclient, so a big thank you to this project. I have converted an application from 1.X (with heavy xml-config) and have managed to get the app up and running, but when I try to show a view I get a NPE in createControl() for:
chkDisplayOnlyErrors = getApplicationConfig().componentFactory().createCheckBox("Visa endast fel");
Been trying to figure this out for almost a day now, but can't find the answer. I have in my opinion, the same config as in http://grepcode.com/project/repo1.maven.org/maven2/dk.navicon/valkyrie-rcp-vldocking-sample/.
Here is a print screen of the view class object taken while debugging createControl(), I find it strange that the applicationConfig is null for thew view object, which is the source of the NPE.
Sorry if this is the wrong forum for questions..