openSourceBim IfcModelService was always empty when i load it - java

I try to load Ifc4 file to deserialize data into a IfcModelService.
For this job i use openSourceBIM IfcPlugin Api using the JsdonDeserializer.
When i launch my code, the IfcModelService are loaded but all attribute are empty only the PackageMetada.
I have no justification for this, i would like acces of the Ifc file for extract informations on elements of the plan (door, window, size etc...)
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.omb</groupId>
<artifactId>ws-metre</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>myservice</name>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.opensourcebim/ifcplugins -->
<dependency>
<groupId>org.opensourcebim</groupId>
<artifactId>ifcplugins</artifactId>
<version>0.0.80</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Apache commons -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Java
package fr.omb.myservice;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.bimserver.deserializers.JsonDeserializer;
import org.bimserver.emf.IdEObjectImpl;
import org.bimserver.emf.IfcModelInterface;
import org.bimserver.emf.PackageMetaData;
import org.bimserver.emf.Schema;
import org.bimserver.ifc.step.deserializer.DetectIfcVersion;
import org.bimserver.ifc.step.serializer.Ifc4StepStreamingSerializerPlugin;
import org.bimserver.models.ifc4.Ifc4Package;
import org.bimserver.models.ifc4.IfcRoot;
import org.bimserver.models.store.DataObject;
import org.bimserver.models.store.StoreFactory;
import org.bimserver.plugins.deserializers.DeserializeException;
import org.eclipse.emf.ecore.EObject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.print.DocFlavor;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
#SpringBootApplication
public class IfcParserApplication {
public static void main(String[] args) {
try {
SpringApplication.run(IfcParserApplication.class, args);
//extract file
Path path = Paths.get("C:\\ToolBox\\Projets\\BIM\\IFC 4\\Ifc4File.ifc");
JsonDeserializer deserializer = new JsonDeserializer();
PackageMetaData packageMetaData = new PackageMetaData(Ifc4Package.eINSTANCE, Schema.IFC4, Paths.get("C:\\tmp"));
deserializer.init(packageMetaData);
IfcModelInterface ifcModel = deserializer.read(Files.newInputStream(path), path.toFile().getName(), FileUtils.sizeOf(path.toFile()), null);
System.out.println("Mon modèle" + ifcModel.toString());
for (Long oid : ifcModel.keySet()) {
EObject eObject = ifcModel.get(oid);
if (eObject.eClass().getEAnnotation("hidden") == null) {
DataObject dataObject = null;
if (eObject instanceof IfcRoot) {
IfcRoot ifcRoot = (IfcRoot)eObject;
String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl)dataObject).setOid(oid);
dataObject.setGuid(guid);
dataObject.setName(name);
System.out.println(dataObject.getGuid());
System.out.println(dataObject.getName());
} else {
dataObject = StoreFactory.eINSTANCE.createDataObject();
dataObject.setType(eObject.eClass().getName());
((IdEObjectImpl)dataObject).setOid(oid);
System.out.println(dataObject.getGuid());
System.out.println(dataObject.getName());
}
}
}
} catch (IOException| DeserializeException dee) {
dee.printStackTrace();
}
}
}

You would need to use a StepDeserializer if you want to deserialize an SPF (STEP physical file). The JsonDeserializer does only make sense when you have the IFC serialized in JSON as done by JsonSerializer. I would expect a SerializerException to be thrown though.
Not that non-streaming versions of JsonDeserializers have been deprecated in the meantime.

Related

Elasticsearch 8.3 configuration in Spring Boot

I have been trying to implement Elastic Search 8.3 with spring boot.
i am getting the below exception:
Cannot convert value of type 'co.elastic.clients.elasticsearch.ElasticsearchClient' to required type 'org.springframework.data.elasticsearch.core.ElasticsearchOperations'
Below is my configuration for elastic search:
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
#Configuration
#EnableElasticsearchRepositories
public class ElasticConfig {
#Bean
public RestClient client() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "test321"));
HttpHost host = new HttpHost("localhost", 9200);
RestClient restClient = RestClient.builder(host)
.setHttpClientConfigCallback(new HttpClientConfigCallback() {
#Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
// TODO Auto-generated method stub
httpClientBuilder.disableAuthCaching();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
}).build();
return restClient;
}
#Bean
public ElasticsearchClient elasticsearchTemplate() {
ElasticsearchTransport transport = new RestClientTransport(client(), new JacksonJsonpMapper());
return new ElasticsearchClient(transport);
}
}
Below is POM:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>aisha</groupId>
<artifactId>courseapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>courseapp</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<guava.version>20.0</guava.version>
<geoip2.version>2.15.0</geoip2.version>
<uap-java.version>1.4.0</uap-java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>${geoip2.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.github.ua-parser</groupId>
<artifactId>uap-java</artifactId>
<version>${uap-java.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.3.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.javafaker/javafaker -->
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Below is test class which call simple query for index product :
#SpringBootTest
public class ElkSpringTest {
#Autowired
private ElasticsearchRestTemplate elasticConfig;
#Test
void contextLoads() {
SearchResponse<ELKProduct> search;
try {
search = elasticConfig.search(s -> s.index("product").size(10), ELKProduct.class);
System.out.println(search.hits().total().value());
for (Hit<ELKProduct> hit : search.hits().hits()) {
System.out.println(hit.source().getId());
}
System.out.println("******ENding *****");
} catch (ElasticsearchException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Since elastic is upgraded to latest version 8.3. I am not able to set up elastic search in spring boot. I usually work with ElasticSearch repository to store the data in my indexs and query it using ElasticsearchOperations.
Current spring-data-elasticsearch(version 4.4) not much compatible with es version 8.3 (>7.17.6).
ES RestHighLevelClient can setApiCompatibilityMode(true) to enables compatibility mode that allows HLRC 7.17 to work with Elasticsearch 8.x. But the compatibility is not very good.
spring-data-elasticsearch(version 5.0) is now compatible with ES 8.5.0
It looks like the RestHighLevelClient is deprecated as of this version.
Check this documentation for implementing the client configuration.

Import issue with com.hazelcast.config.MaxSizeConfig

I'm working on a Spring boot tutorial and I'm a bit stuck on this section of the video. The narrator in the video uses the MaxSizeConfig import inside a return statement. Trying out the same line, I'm getting an error saying that MaxSizeConfig can't be resolved to a type. Checking out the docs for hazelcast, the import exists. Could I get some direction in what I'm doing wrong with my code?
Here's my pom.xml:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.stephen.springweb</groupId>
<artifactId>productrestapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>productrestapi</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-tomcat
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Here's the code that's trying to use MaxSizeConfig:
package com.stephen.springweb.productrestapi.config;
import org.springframework.context.annotation.Bean;
import com.hazelcast.config.Config;
import com.hazelcast.config.EvictionPolicy;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.MaxSizePolicy;
import org.springframework.context.annotation.Configuration;
#Configuration
public class ProductCacheConfig {
#Bean
public Config cacheConfig() {
return new Config()
.setInstanceName("hazel-instance")
.addMapConfig(new MapConfig()
.setName("product-cache")
.setTimeToLiveSeconds(3000)
.setMaxSizeConfig(new MaxSizeConfig(200, MaxSizePolicy.FREE_HEAP_SIZE))
.setEvictionPolicy(EvictionPolicy.LRU)
);
}
}
Thank you.
For version 4, use setEvictionConfig.
https://docs.hazelcast.org/docs/4.0/javadoc/com/hazelcast/config/EvictionConfig.html
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.hazelcast.config.Config;
import com.hazelcast.config.EvictionConfig;
import com.hazelcast.config.EvictionPolicy;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.MaxSizePolicy;
#Configuration
public class ProductCacheConfig {
#Bean
public Config cacheConfig() {
return new Config()
.setInstanceName("hazel-instance")
.addMapConfig(new MapConfig()
.setName("product-cache")
.setTimeToLiveSeconds(3000)
.setEvictionConfig(new EvictionConfig()
.setSize(200)
.setMaxSizePolicy(MaxSizePolicy.FREE_HEAP_SIZE)
.setEvictionPolicy(EvictionPolicy.LRU)
)
);
}
}
Which version of hazelcast are you using? More precisely, which is inherited from Spring. The setMaxSizeConfig method has been removed in later versions of hazelcast, for example 4.2 https://docs.hazelcast.org/docs/4.2/javadoc/com/hazelcast/config/MapConfig.html
But in version 3.6 it was still https://docs.hazelcast.org/docs/3.6/javadoc/com/hazelcast/config/MapConfig.html
The differences between versions 3 and 4 are significant.

Can't find the request for http://localhost:8082/{params}'s Observer

I have a very simple Java REST service code concept here.
The problem is that when I am hitting the URL the below message is showing up in the console:
Can't find the request for http://localhost:8082/REST/services/patientservices/getallpatients's Observer
I am using cxf.jaxrs.component-scan=true for spring to read the annotations.
Below are the classes and configuration file:
pom.xml:
<?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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.11.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.mayukh.rs</groupId>
<artifactId>jaxrs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>jaxrs</name>
<description>JAX RS</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
PatientService.java:
package com.mayukh.rs;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import com.mayukh.rs.model.Patient;
#Path("/patientservices")
public interface PatientService {
#Path("/getallpatients")
#GET
List<Patient> getPatients();
}
PatientServiceImpl.java:
package com.mayukh.rs;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.mayukh.rs.model.Patient;
#Service
public class PatientServiceImpl implements PatientService {
Map<Long, Patient> patients = new HashMap<>();
long currId = 123;
public PatientServiceImpl() {
init();
}
public void init() {
Patient patient = new Patient();
patient.setId(currId);
patient.setName("Mayukh");
patients.put(patient.getId(), patient);
}
#Override
public List<Patient> getPatients() {
Collection<Patient> results = patients.values();
List<Patient> response = new ArrayList<>(results);
return response;
}
}
application.properties:
server.port=8082
cxf.jaxrs.component-scan=true
server.servlet.context-path=/REST
There was a mistake in the pom.xml file.
Instead of jaxws dependency it should be jaxrs dependency.
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
<version>3.4.3</version>
</dependency>

Problem with GraphQL finding method on queryResolver

I'm working on a GraphQL java API project and i'm having problems with the Query not finding the methods in the Query.java (QueryResolver)
I can't see an error on this code but aparently it has one ':D
PS: I use java open JDK 11
the error: (full stacktrace on https://pastebin.com/cpVRpdsj)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.ServletRegistrationBean]: Factory method 'graphQLServlet' threw exception; nested exception is com.coxautodev.graphql.tools.FieldResolverError: No method or field found with any of the following signatures (with or without one of [interface graphql.schema.DataFetchingEnvironment] as the last argument), in priority order:
com.example.GraphQLRProject.core.Query.findAllPessoas()
com.example.GraphQLRProject.core.Query.getFindAllPessoas()
com.example.GraphQLRProject.core.Query.findAllPessoas
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
... 59 common frames omitted
my pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>GraphQLRProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>GraphQLRProject</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<!--<kotlin.version>1.3.10</kotlin.version> -->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
-->
<!--
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>6.0.1</version>
</dependency>
-->
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>11.0</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-servlet</artifactId>
<version>6.1.3</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.6</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<!-- GraphQL end -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
my Query.java
package com.example.GraphQLRProject.core;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.example.GraphQLRProject.model.Pessoa;
import com.example.GraphQLRProject.repository.PessoaRepository;
#Component
public class Query implements GraphQLQueryResolver {
#Autowired
PessoaRepository pessoaRepository;
List<Pessoa> findAllPessoas() {
return pessoaRepository.findAll();
}
}
my main application
package com.example.GraphQLRProject;
import java.util.TimeZone;
import javax.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import com.coxautodev.graphql.tools.SchemaParser;
import com.example.GraphQLRProject.core.Mutation;
import com.example.GraphQLRProject.core.Query;
import com.example.GraphQLRProject.util.DateScalar;
import graphql.schema.GraphQLSchema;
import graphql.servlet.SimpleGraphQLHttpServlet;
#ComponentScan(basePackageClasses = GraphQlrProjectApplication.class)
#SpringBootApplication(scanBasePackages = "com.example")
#EntityScan("com.example")
#EnableJpaRepositories("com.example")
#SuppressWarnings({"rawtypes", "unchecked"})
public class GraphQlrProjectApplication {
public static void main(String[] args) {
SpringApplication.run(GraphQlrProjectApplication.class, args);
}
#PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("America/Recife"));
}
#Bean
public ServletRegistrationBean graphQLServlet() {
return new ServletRegistrationBean(SimpleGraphQLHttpServlet.newBuilder(buildSchema()).build(), "/graphql");
}
private static GraphQLSchema buildSchema() {
return SchemaParser
.newParser()
.file("schema.graphqls")
.resolvers(new Query(), new Mutation())
.scalars(DateScalar.DATE)
.build()
.makeExecutableSchema();
}
}
and my schema.graphqls
schema {
query: Query
mutation: Mutation
}
type Query {
findAllPessoas: [Pessoa]
}
type Mutation {
savePessoa(novo: PessoaInput): Pessoa
}
type Pessoa {
id: ID!
nome: String!
cpf: String!
email: String!
}
input PessoaInput{
nome: String!
cpf: String!
email: String!
}
The problem was that the method was not public ...
big facepalm for me ':D

Java Spring - missing type SolrClient, MulticoreSolrServerFactory

I am trying to implement Solr into my Java Spring application, however I have troubles with dependencies, since STS cannot find SolrClient and MultiCoreSolrServerFactory. Here is the class that is causing me troubles:
package lt.gerasolutions.gsm.core.classifiers.domain;
import javax.annotation.Resource;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.repository.SolrCrudRepository;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
import org.springframework.data.solr.server.support.HttpSolrClientFactoryBean;
#Configuration
#EnableSolrRepositories(basePackages={"lt.gerasolutions.gsm.core.solrRepositories"},
multicoreSupport=true)
public class SolrContext {
static final String SOLR_HOST = "solr.host";
#Resource
private Environment environment;
#Bean
public SolrServer solrServer() {
String solrHost = environment.getRequiredProperty(SOLR_HOST);
SolrServer server = new HttpSolrServer(solrHost);
MulticoreSolrServerFactory factory;
//I was told to use this factory to return a server, but eclipse cannot find it unfortunately.
}
#Bean (name = "EN")
public SolrTemplate solrEn(){
return new SolrTemplate(solrServer());
//The type org.apache.solr.client.solrj.SolrClient cannot be resolved. It is indirectly referenced from required .class files
}
#Bean (name = "LT")
public SolrTemplate solrLt(){
return new SolrTemplate(solrServer());
}
}
My dependencies are managed by maven, and this is its pom file:
<?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.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>a</name>
<description></description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>
spring-boot-starter-data-elasticsearch
</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>6.0.0</version>
<exclusions>
<exclusion>
<artifactId>jdk.tools</artifactId>
<groupId>jdk.tools</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Check the solrj jar version in dependencies.
Since spring boot is having a dependency of 4.10.4, new version doesnt get override. The old version does not have Cloud classes.
You can manually add
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>5.5.1</version>
</dependency>
You will have new version then.

Categories