Connecting to a running Gemfire server - spring-data-gemfire

Using gfsh I have started a locator on my PC. How do I connect to this locator using spring-data-gemfire.
Here is the my locator
gfsh>start locator --name=locator1
Locator in /Users/adas/locator1 on 10.1.51.200[10334] as locator1 is currently online
Now I have the following class to connect to this locator
#ClientCacheApplication(locators = {
#ClientCacheApplication.Locator(host = "10.1.51.200", port = 10334)
})
#EnableEntityDefinedRegions(basePackageClasses = Person.class,
clientRegionShortcut = ClientRegionShortcut.LOCAL)
#EnableGemfireRepositories
public class GemfiretestApplication {
public static void main(String[] args) {
SpringApplication.run(GemfiretestApplication.class, args);
}
On compiling I get the following error
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemfireCache': FactoryBean threw exception on object creation; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178)

Given the INCREDIBLY limited information provided (partial stacktrace, no versions, no maven/gradle build files) I could only venture a guess at your problem. I think #juanramos has the correct idea.
I'm testing with:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Lovelave-SR6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
AND
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
Without the full stack trace I believe that I see your error. If then add the following exclusion, this problem disappears.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.4.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
If this does not solve your problem, please forward your complete stacktrace... or maybe the last "Caused by:...." statement and/or list of your dependencies.

Related

Working example of Spring boot reactive and EventSource

I'm trying to have a working spring boot with reactive mongodb and EventSource.
However, I'm facing issues with the repetitive reopening of the connection because it's closed by the server. I even have some doubt if this could really work since I didn't find any working example with a reactive db and Event source...
Could you please point me to a working example or tell me what's wrong with my code?
Here the main parts of the code:
pom.xml
<properties>
<java.version>1.8</java.version>
<junit-jupiter.version>5.3.2</junit-jupiter.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
</parent>
<dependencies>
<!-- webflux reactive -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<!-- thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- exclude junit 4, prefer junit 5 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- junit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
As you see in the pom, I'm using the embedded tomcat (I already tried with Netty, the default spring boot server...).
Also, I'm deploying the app to any remote server but just trying on my local (windows 10).
Web:
let source = new EventSource("/comment/stream");
source.addEventListener("message", function (event) {
// These events are JSON, so parsing and DOM fiddling are needed
var comment = JSON.parse(event.data);
console.log(comment );
});
source.addEventListener("error", function (event) {
console.log("error", event);
this.close();
});
RestController:
#RestController
public class CommentController {
#Autowired
private CommentRepository commentRepository;
#PostMapping(path = "/comment")
public Mono<Comment> comment(#RequestBody Comment comment) {
return this.commentRepository.save(comment);
}
#GetMapping(path = "/comment/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Comment> feed() {
return this.commentRepository.findAll();
}
}
DB Repository:
#Repository
public interface CommentRepository extends ReactiveSortingRepository<Comment, String> {
Flux<Comment> findAll();
}
Again, the web client that uses EventSource, keeps reconnecting every second because the connection is closed by the server.
Thank you!
Im not really sure, you are giving us too little information as to why your connection is closing. No logs, and you are not disclosing anything about where it being deployed.
i will only answer this question based on personal experience. I deployed an application to heroku that uses event streams and they have a proxy/loadbalancer infront of every application that will kill any connection that does not send anything after up to 60 sec.
As mentioned here Why are event sources closed after 30-60 sec it confirmes what i have been noticing.
To work around this you can if using websockets implement ping/pong messages or if using ServerSentEvents as i did, i implemented keep alive messages.
.GET("", accept(TEXT_EVENT_STREAM), request -> ok()
.contentType(TEXT_EVENT_STREAM)
.header("Cache-Control", "no-transform")
.body(Flux.merge(myHandler.getEvents()),
Flux.interval(Duration.ofSeconds(15))
.map(aLong -> ServerSentEvent.builder()
.comment("keep alive")
.build())),
new ParameterizedTypeReference<List<MyClass>>() {}))
I have taken this code snippet from one of my projects. Here you can see that i merge with my current stream a flux that at given intervals (15 sec) will emit a ServerSentEvent with only a keep alive comment. Since it is a comment it will get ignored by the client.
Just need to mention, the regular stream myHandler.getEvents returns data wrapped in ServerSentEvents.

Mongo Java Driver version mismatch with spring framework

I have springboot (2.0.4) application with Mongo Java driver version 3.11.2. When upgrading the application for mongo java driver to version 4.1.0 to use IAM authentication feature of new mongo java driver, the changes are breaking with overall spring framework.
MongoTemplate Bean code:
#Bean
public MongoClient mongoClient() {
ConnectionString connectionString = new ConnectionString(
("mongodb://connectionString:goesHere"));
MongoClient mongoClient = MongoClients.create(connectionString);
return mongoClient;
}
#Bean
public MongoTemplate mongoTemplate(MongoClient mongoClient) {
return new MongoTemplate(mongoClient, mongoDB);
}
Dependencies:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</exclusion>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</exclusion>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
</exclusion>
</exclusions>
</dependecy>
Deployment error with Mongo Java Driver 4.1.0:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.util.Assert.noNullElements(Ljava/util/Collection;Ljava/lang/String;)V
When looking into this issue, found that I need to add sping-core (5.2.5 or later) for this, that in turn is asking for other spring dependencies to be on same version.
This whole defeats the goal of having spring boot for ease of dependency management.
It feels like spring ecosystem has become so complex, that upgrading mongo-java-driver would need the un-necessary work of upgrading the whole application to newer version of springboot which are not backward compatible and will break the application build. Any suggestions to get rid of this issue.
i'm using these pom you can give it a try for mongo-3.8.2 and spring-data :1.10.0
. Make sure you are not missing "spring-data-commons-core jar"
<properties>
<mongo.java.driver.version>3.8.2</mongo.java.driver.version>
<spring.data.version>1.10.0.RELEASE</spring.data.version>
</properties>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>${mongo.java.driver.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>${spring.data.version}</version>
</dependency>

Spring batch Gemfire 9.6 connection error - Caused by: java.io.IOException: Unable to write to deploy directory

I am using Spring batch to load data into gemfire using
#Bean
public GemfireTemplate gemFireTemplate(ClientRegionFactory<Object,
Object> factory) {
GemfireTemplate template = new GemfireTemplate();
template.setRegion("regionName");
return template;
}
POM:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-gemfire</artifactId>
<version>1.5.16.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-geode</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-core</artifactId>
<version>9.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-common</artifactId>
<version>9.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-cq</artifactId>
<version>9.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-wan</artifactId>
<version>9.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-json</artifactId>
<version>9.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-lucene</artifactId>
<version>9.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.3.RELEASE</version>
</dependency>
Logs :
[info 2019/09/11 22:29:22.836 CDT <main> tid=0x1] GemFireCache[id = 892555958; isClosing = true; isShutDownAll = false; created = Wed Sep 11 22:29:20 CDT 2019; server = false; copyOnRead = false; lockLease = 120; lockTimeout = 60]: Now closing.
[error 2019/09/11 22:29:22.913 CDT <main> tid=0x1] java.lang.RuntimeException: java.io.IOException: Unable to write to deploy directory: /data/khan/vaquar/dataloader
java.lang.RuntimeException: java.io.IOException: Unable to write to deploy directory: /data/khan/vaquar/dataloader
at org.apache.geode.internal.JarDeployer.loadPreviouslyDeployedJarsFromDisk(JarDeployer.java:410)
at org.apache.geode.internal.cache.GemFireCacheImpl.initialize(GemFireCacheImpl.java:1191)
at org.apache.geode.internal.cache.GemFireCacheImpl.basicCreate(GemFireCacheImpl.java:758)
at org.apache.geode.internal.cache.GemFireCacheImpl.createClient(GemFireCacheImpl.java:731)
at org.apache.geode.cache.client.ClientCacheFactory.basicCreate(ClientCacheFactory.java:262)
at org.apache.geode.cache.client.ClientCacheFactory.create(ClientCacheFactory.java:212)
at com.syf.gemfire.jdbc.dataloader.config.FullBatchConf.clientCache(FullBatchConf.java:205)
at com.syf.gemfire.jdbc.dataloader.config.FullBatchConf$$EnhancerBySpringCGLIB$$749d49c1.CGLIB$clientCache$5(<generated>)
at com.syf.gemfire.jdbc.dataloader.config.FullBatchConf$$EnhancerBySpringCGLIB$$749d49c1$$Fast
Caused by: java.io.IOException: Unable to write to deploy directory: /data/khan/vaquar/dataloader
at org.apache.geode.internal.JarDeployer.verifyWritableDeployDirectory(JarDeployer.java:333)
at org.apache.geode.internal.JarDeployer.loadPreviouslyDeployedJarsFromDisk(JarDeployer.java:389)
and
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.geode.cache.client.ClientCache]: Factory method 'clientCache' threw exception; nested exception is java.lang.RuntimeException: java.io.IOException: Unable to write to deploy directory:/data/khan/vaquar/dataloader
Analysis:
Pivotal jars required write permissions when start geode connection with gemfire cluster .
Pivotal code :
https://github.com/ashishtadose/gemfire-xd/blob/master/gemfire-core/src/main/java/com/gemstone/gemfire/internal/JarDeployer.java
Pivotal Doc:
- https://gemfire.docs.pivotal.io/98/geode/configuring/cluster_config/deploying_application_jars.html
If gemfire.properties is specified then Geode locator fails to start
https://www.mail-archive.com/issues#geode.apache.org/msg17105.html
https://issues.apache.org/jira/browse/GEODE-5000?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel
Pivotal doc says if we can remove "deploy-working-dir"inside "gefire.properties" will resolve issue else use "-Dgemfire.deploy-working-dir=/temp/
Problem :
inside Spring batch we are not configuring any gemfire properties , how to fix it in GemfireTemplate code ?
The issue is clearly the same as the one described by the Geode Ticket you attached to the question, GEODE-5000. This particular ticket is fixed in Geode 1.6.0 and, according to the Pivotal GemFire User Guide, specifically the Release Notes, GemFire 9.5 is based on Geode 1.6.0, so you should be using that version instead of 9.3.0 to get rid of the problem.
As a side note, you shouldn't be arbitrarily mixing and matching spring-data-gemfire and gemfire versions as several issues might rise, please follow the Spring Data for Pivotal GemFire Version Compatibility Matrix to avoid issues.
Hope this helps. Cheers.

Why does my flapdoodle Embedded MongoDB test fail to run? (creating 'embeddedMongoServer' could not start process EOF)

I'm having trouble getting my brand new project to build. I used https://start.spring.io/ to generate a fresh new Spring 2.0 MongoDB Maven project, and I want to have an embedded MongoDB database for my integration tests. The spring initializer added a dependency for de.flapdoodle.embed.mongo to that end.
But every time I try to run a "mvn clean package", I get the following error during my test:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'embeddedMongoServer' defined in class path resource
[org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]:
Invocation of init method failed; nested exception is java.io.IOException:
Could not start process: <EOF>
at de.flapdoodle.embed.mongo.AbstractMongoProcess.onAfterProcessStart(AbstractMongoProcess.java:79) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.process.runtime.AbstractProcess.<init>(AbstractProcess.java:116) ~[de.flapdoodle.embed.process-2.0.2.jar:na]
at de.flapdoodle.embed.mongo.AbstractMongoProcess.<init>(AbstractMongoProcess.java:53) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.mongo.MongodProcess.<init>(MongodProcess.java:50) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:44) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:34) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.process.runtime.Executable.start(Executable.java:108) ~[de.flapdoodle.embed.process-2.0.2.jar:na]
What am I missing?
My Application file is pretty straightforward:
#SpringBootApplication
public class NewnewinternetApplication {
public static void main(String[] args) {
SpringApplication.run(NewnewinternetApplication.class, args);
}
}
My Config file is very simple:
#Configuration
#EnableMongoRepositories
#ComponentScan(basePackages = "com.snoop.dougg.newnewinternet")
public class AppConfig {
#Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/");
resolver.setSuffix(".html");
return resolver;
}
}
I have two simple controllers returning just static output for now.
I have a little document:
#Document(collection = "user")
public class User implements Serializable {
protected static final long serialVersionUID = -1L;
#Id
private String id;
private String username;
private String firstName;
private String lastName;
public User() {}
public User(String username, String firstName, String lastName) {
this.username = username;
this.firstName = firstName;
this.lastName = lastName;
}
//Getters, setters, and equals and hash code methods...
}
And then a silly little test:
#RunWith(SpringRunner.class)
//#SpringBootTest -> Doesn't work either
#DataMongoTest
public class NewnewinternetApplicationTests {
#Autowired
private MongoTemplate mongoTemplate;
#Test
public void sillyLittleTest() {
mongoTemplate.save(new User("sdoug", "Snoop", "Dougg"));
Assert.notNull(
mongoTemplate.find(
new Query(Criteria.where("firstName").is("Snoop")), User.class),
"Couldn't find by first name!");
}
}
And then my pom file, which I really just left alone:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.snoop.dougg.newnewinternet</groupId>
<artifactId>NewNewInternet</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>NewNewInternet</name>
<description>A new new internet</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<azure.version>2.0.1</azure.version>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.M9</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-active-directory-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-keyvault-secrets-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-spring-boot-bom</artifactId>
<version>${azure.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
I was in the same situation, and I could resolve it using #DirtiesContext on this way:
#DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class CommoditiesApplicationTests {
}
Commenting out the following lines in application.properties and placing them in a different profile can also work. I found it here
spring.data.mongodb.database=
spring.data.mongodb.host=
spring.data.mongodb.port=
Usually already running mongodb instance is the source of the issue. I would start with checking if anything occupies default mongodb port - 27017.
In my case the 32 bit mongodb client was downloaded instead of the 64 bit one.
embedded.mongo library uses BitSize class to determine the OS architecture. In my system System.getProperty("os.arch") was not returning a value listed in the if statement.
I solved the problem by setting os.arch system property to x86_64 (one of the values used by BitSize to return B64) in my application main.
#SpringBootApplication
public class Application {
public static void main(String[] args) {
System.setProperty("os.arch", "x86_64");
SpringApplication.run(Application.class, args);
}
}
Note: System.getProperty("os.arch") will return the wrong value if you use a 32 bit java version to run your application on a 64 bit system!
my error message was exactly like this
2022-03-15 10:57:00.053 WARN 7196 --- [ Test worker] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Unsatisfied dependency expressed through method 'embeddedMongoServer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoConfiguration' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.flapdoodle.embed.mongo.config.MongodConfig]: Factory method 'embeddedMongoConfiguration' threw exception; nested exception is java.lang.IllegalStateException: Set the spring.mongodb.embedded.version property or define your own MongodConfig bean to use embedded MongoDB
so, I add property in my application.yml file.
spring.mongodb.embedded.version: 3.2.3
and, solved it.
chances are the instance of mongodb downloaded through the spring plugin is 32 & you are running on 64 bit java or vice versa. Please confirm if there is any other way you have identified the fix.
I had the pretty same scenario here, and solved it using
<dependency>
<groupId>com.github.fakemongo</groupId>
<artifactId>fongo</artifactId>
<version>2.1.1</version>
<scope>test</scope>
</dependency>
instead of de.flapdoodle.embed.mongo
In my case, the socket file was still around.
To get to the underlying issue, I wanted the console logging output, I put a breakpoint in the else clause of the AbstractMongoProcess::onAfterProcessStart (which is hit on failure).
Here you have access to the logWatch and can run a System.out.println(logWatch.output.toString()); in debug mode to get the mongo console out. For my issue, the output said SocketException: Address already in use
Trying commands suggested such as sudo lsof -iTCP -sTCP:LISTEN -n -P did not work for me (nothing listed in my case)
I found another SO answer that said to run ls -lrta /tmp | grep .sock
The .sock file was still there from a previous run (Apparently I had interrupted my tests)
Deleting this file solved the issue.
The error is due to the package de.flapdoodle.embed which was used for Embedded Mongo, use a stable version of it 3.5.0
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>3.5.0</version>
<scope>test</scope>
</dependency>
add it in the pom.file(add the version to it).Then update maven it should work fine
My case was a bit special, but maybe this help someone else too to resolve this.
If, by any chance, you are using win 10 and you have already a MongoDB running as a service (in my case it was an earlier version - v3.4 - running), then try to stop the service, and run the test afterwards.
Try to add #DirtiesContext to the test class level.
I deleted the 'mongo' dir in my appdata/temp and that is when I caught my McAfee quarantining my embedded mongo. I turned OFF McAfee and deleted the temp mongo again and then all ran great...
Same problem.
spring.data.mongodb.port was 27017 in application.properties. I changed it to 0. When 0 is used, a random port is assigned instead.
My Integration Test is like below:
#RunWith(SpringRunner.class)
#DataMongoTest
public class IntegrationTestIT { ... }
I'm using de.flapdoodle.embed:de.flapdoodle.embed.mongo:3.4.6.
I had the same issue. Refer to this github issue for the solution if your problem is related to flapdoodle: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/issues/427
Just increase the flapdoodle version >=3.5.0
and if possible increase also spring-boot version to the latest

Missing dependency for method

I am running REST Web Service and after adding some new Web Services I got some errors.
Why do I get these errors?
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public entities.ProyectoHasPersona service.ProyectoHasPersonaRESTFacade.find(entities.ProyectoHasPersonaPK) at parameter at index 0
SEVERE: Method, public entities.ProyectoHasPersona service.ProyectoHasPersonaRESTFacade.find(entities.ProyectoHasPersonaPK), annotated with GET of resource, class service.ProyectoHasPersonaRESTFacade, is not recognized as valid resource method.
SEVERE: Missing dependency for method public javax.ws.rs.core.Response service.ProyectoHasPersonaRESTFacade.remove(entities.ProyectoHasPersonaPK) at parameter at index 0
SEVERE: Method, public javax.ws.rs.core.Response service.ProyectoHasPersonaRESTFacade.remove(entities.ProyectoHasPersonaPK), annotated with DELETE of resource, class service.ProyectoHasPersonaRESTFacade, is not recognized as valid resource method.
I am using Jersey 1.1.1, these are my dependencies:
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_core</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Looks like methods service.ProyectoHasPersonaRESTFacade.find() and service.ProyectoHasPersonaRESTFacade.remove() take one parameter which is not annotated (i.e. it means the methods expect the request entity to be passed into this parameter), however, these methods are mapped to HTTP GET and DELETE. Neither HTTP GET nor HTTP DELETE can have an entity. So the unannotated parameter on the corresponding Java methods does not make sense.
You can get the ID/PK of the object to be retrieved/deleted e.g. by putting it either in a path parameter or query parameter.