Bean creation exception on FactoryBean type check when creating RmiRegistryFactoryBean - rmi

I get the following exception 8 times:
WARN DefaultListableBeanFactor - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'rmiRegistryFactoryBean': Requested bean is currently in creation: Is there an unresolvable circular reference?
When I create the following bean in my context:
#Bean
public RmiRegistryFactoryBean rmiRegistryFactoryBean() {
RmiRegistryFactoryBean rmiRegistryFactoryBean = new RmiRegistryFactoryBean();
rmiRegistryFactoryBean.setPort(rmiConfig.getPort());
rmiRegistryFactoryBean.setAlwaysCreate(true);
return rmiRegistryFactoryBean;
}
There is no explicit circular reference.

Related

I get exception with axon-mongo 4.5, spring boot 2.4.3 and mongodb 4.2 in AxonConfig class

When running the project I get this exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'axonMongoTemplate' defined in com.springbank.user.core.configuration.AxonConfig: Bean
instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.axonframework.extensions.mongo.MongoTemplate]: Factory method 'axonMongoTemplate'
threw exception; nested exception is java.lang.IllegalStateException: #Bean method
AxonConfig.mongo called as bean reference for type [com.mongodb.MongoClient] but overridden
by non-compatible bean instance of type [com.mongodb.client.internal.MongoClientImpl].
Overriding bean of same name declared in: class path resource
[org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.axonframework.extensions.mongo.MongoTemplate]: Factory method 'axonMongoTemplate'
threw exception; nested exception is java.lang.IllegalStateException: #Bean method
AxonConfig.mongo called as bean reference for type [com.mongodb.MongoClient] but overridden
by non-compatible bean instance of type [com.mongodb.client.internal.MongoClientImpl].
Overriding bean of same name declared in: class path resource
[org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]
Caused by: java.lang.IllegalStateException: #Bean method AxonConfig.mongo called as bean
reference for type [com.mongodb.MongoClient] but overridden by non-compatible bean instance
of type [com.mongodb.client.internal.MongoClientImpl]. Overriding bean of same name declared
in: class path resource
[org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]
this is my axon configuration class:
#Configuration
public class AxonConfig {
#Value("${spring.data.mongodb.host:127.0.0.1}")
private String mongoHost;
#Value("${spring.data.mongodb.port:27017}")
private int mongoPort;
#Value("${spring.data.mongodb.database:user}")
private String mongoDatabase;
#Bean
public MongoClient mongo() {
var mongoFactory = new MongoFactory();
mongoFactory.setMongoAddresses(Collections.singletonList(new ServerAddress(mongoHost, mongoPort)));
return mongoFactory.createMongo();
}
#Bean
public MongoTemplate axonMongoTemplate() {
return DefaultMongoTemplate.builder()
.mongoDatabase(mongo(), mongoDatabase)
.build();
}
...
}
The spring boot version and dependencies I use are:
org.springframework.boot:spring-boot-starter-parent:2.4.3
org.axonframework:axon-spring-boot-starter:4.5.9
org.axonframework.extensions.mongo:axon-mongo:4.3
this is my application.properties:
#spring
server.port=8082
#mongodb
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=user
spring.main.allow-bean-definition-overriding=true
spring.main.allow-circular-references=true
I think you can just remove the MongoClient Bean, as Spring Boot is already doing that for you.
After several tests of dependency versions, I found the dependencies that did not conflict with each other.
Here's the list of versions used:
Java JDK 14
spring-boot-starter-parent:2.2.6.RELEASE
axon-spring-boot-starter:4.3.1
lombok:1.18.20
Using other versions of spring boot exceptions occurred.

Getting the BeanCreationException after adding Swagger Implementation in Springboot RestApi

Below i have added the code in which after adding Swagger2feature i'm getting
BeanCreationException , BeanInstantiationException and NoSuchMethodError(io.swagger.jaxrs.config.BeanConfig.setUsePathBasedConfig(Z)V)
Main Class:
public static void main(String[] args) {
SpringApplication.run(TechpubsServicesSBApp.class, args);
}
#Bean
public Server rsServer() {
JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
endpoint.setBus(bus);
endpoint.setServiceBeans(Arrays.<Object>asList(testImpl));
endpoint.setAddress("/");
endpoint.setProviders(Arrays.<Object>asList(testExceptionMapper));
endpoint.setProvider(new JacksonJsonProvider());
Swagger2Feature swagger2Feature = new Swagger2Feature();
swagger2Feature.setTitle("Test API");
swagger2Feature.setVersion(deployedVersion.concat("(").concat(deployedInstance.toUpperCase()).concat(")"));
swagger2Feature.setPrettyPrint(true);
swagger2Feature.setSupportSwaggerUi(true);
endpoint.setFeatures(Collections.singletonList(swagger2Feature));
return endpoint.create();
}</i>
Error :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rsServer' defined in com.geaviation.techpubs.ws.TechpubsServicesSBApp: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.cxf.endpoint.Server]: Factory method 'rsServer' threw exception; nested exception is java.lang.NoSuchMethodError: io.swagger.jaxrs.config.BeanConfig.setUsePathBasedConfig(Z)V
Have anyone faced similar kind of error ?
I faced a similar kind of error. My problem was that I had multiple swagger dependencies in my build.gradle. Before I got rid of the error my build.gradle looked similar to this:
compile "org.webjars:swagger-ui:3.9.2"
compile "io.swagger:swagger-annotations:1.5.10"
compile "io.swagger:swagger-jaxrs:1.5.0"
What solved the problem was a build.gradle looking like this:
compile "org.webjars:swagger-ui:3.9.2"
I removed the io.swagger dependencies and it worked for me. A final rsServer setup could look something like this later and hopefully work with the swagger2feature enabled ;).
#Bean
public Server rsServer() {
JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
endpoint.setBus(bus);
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJaxbJsonProvider());
endpoint.setProviders(providers);
endpoint.setServiceBeans(Arrays.<Object>asList(myService()));
endpoint.setAddress("/");
endpoint.getFeatures().add(serviceConfiguration.swagger2Feature());
return endpoint.create();
}

Spring data error

I have the following class
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = {"classpath:my-ctx.xml"})
public class UserTests {
#Inject
private ApplicationContext applicationContext;
private UserRepository getUserRepository() {
return (UserRepository)applicationContext.getBean("userRepository", CrudRepository.class);
}
#Test
public void someTest() {
User user = new User();
user.setName("John Doe");
getUserRepository().save(user);
}
}
Running the test, I get the following error
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException
...
root cause is
org.datanucleus.api.jpa.metamodel.SingularAttributeImpl.isVersion(SingularAttributeImpl.java:79)
org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.findVersionAttribute(JpaMetamodelEntityInformation.java:92)
org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:78)
org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getMetadata(JpaEntityInformationSupport.java:65)
org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:146)
org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:84)
org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:67)
...
where VersionMetaData vermd = mmd.getAbstractClassMetaData().getVersionMetaData(); is null.
Is this a bug?
I know that I can put something like #Inject UserRepository userRepository;, but taking into account how Spring Data works, these two should have the same result, right? And anyway the result will be the same error.
I'm using Spring data 1.4.1, DataNucleus 3.3.2, Spring 3.2.4.
Actually this is a DataNucleus bug and I filled in a bug report (with test and fix patch included): http://www.datanucleus.org/servlet/jira/browse/NUCJPA-250.
My workaround was to switch back to Spring Data 1.3.0.

How to see nested exceptions trace, hidden by Spring?

When I am debugging Spring application in Eclipse, I am getting long exception chains. For example, I have
Error creating bean with name '...' defined in file [...Tester.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property '...' threw exception; nested exception is java.lang.IllegalArgumentException: ...
And so on. Multiple stacks with exceptions inside Spring, which is uninteresting. It should be my exceptions somewhere below, but Spring does not show them.
And I can't click into exception and navigate to problem place as usual.
How to say Spring to output all exceptions?
UPDATE
Below is the full output. One can see that the place where IllegalArgumentException occurred was probably truncated.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybean' defined in file [D:\mypath\myconfig.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'myproperty' threw exception; nested exception is java.lang.IllegalArgumentException: my exception message
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.FileSystemXmlApplicationContext.(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.(FileSystemXmlApplicationContext.java:84)
at springtests.SpringRunner.main(SpringRunner.java:8)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'target.partner' threw exception; nested exception is java.lang.IllegalArgumentException: Illegal frame length 1 in explicit constructor
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
... 13 more
Because there are potentially multiple exceptions, you need to catch the PropertyBatchUpdateException and call getPropertyAccessExceptions() to examine the stack trace of the particular exception.
Edit
Actually I'm not quite sure what's going on here
Here is PropertyBatchUpdateException's printStackTrace method:
public void printStackTrace(PrintWriter pw) {
synchronized (pw) {
pw.println(getClass().getName() + "; nested PropertyAccessException details (" +
getExceptionCount() + ") are:");
for (int i = 0; i < this.propertyAccessExceptions.length; i++) {
pw.println("PropertyAccessException " + (i + 1) + ":");
this.propertyAccessExceptions[i].printStackTrace(pw);
}
}
}
It should be including the nested stack traces. Are you using the latest version of Spring?
Edit:
The best I can suggest is to run in debug mode, then put a breakpoint at AbstractAutowireCapableBeanFactory.java:1361 and see what's going on.

Grails bean config in resources.groovy fails in Eclipse STS

We're using Eclipse STS for a simple Grails project. We started with something simple to understand the basics, and this is about as basic as it gets. The project has a simple controller and a java bean wired through resources.groovy. No matter what we do, we can't seem to get the bean wired properly, Grails complains that the bean property is not writable or may not have a getter/setter....
/* TestBean.groovy */
class TestBean {
def message
String getMessage(){
return message
}
}
.
/* resources.groovy */
import com.ofi.test.TestBean;
beans = {
helloWorldBean( TestBean){
message = "HelloWorld"
}
}
.
/* TestController */
class TestController {
def index = { }
def helloWorldBean
def show = {
def message = helloWorldBean.message
render message
}
}
.
/* UrlMappings.groovy */
class UrlMappings {
static mappings = {
"/test/$var"(controller:"Test"){
action = [GET: "get"]
}
}
.
The project compiles, but we get the following error message when the app loads up in Eclipse (we can't even get to the controller, the TestBean config is failing)
2011-08-10 11:18:55,252 [main] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'helloWorldBean': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'message' of bean class [com.ofi.test.TestBean]: Bean property 'message' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloWorldBean': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'message' of bean class [com.ofi.test.TestBean]: Bean property 'message' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
Since your bean is a groovy bean, you don't even need the accessors. The following should be fine:
class TestBean {
def message
}
In your case, the error's probably occurring because the message field is typed as a def, but your accessor is typed as a String. If you must have the accessor there, try typing them the same.
You can add more fields in Bean class and use them into Controller like-
class TestBean {
static constraints = {
}
String message
String name
def demo
}