【发布时间】:2021-06-29 15:09:54
【问题描述】:
我正在使用 spring boot 实现 ignite。我只使用 java 配置了我的 ignite 实例。我还创建了两个实体。我可以使用 ignite 的基本 crud 命令,但我无法编写自己的 sql 查询来查询表。它显示 IgniteException: table not found。
Item.java
import java.io.Serializable;
@Data
public class Item implements Serializable {
private static final long serialVersionUID = -2974414641088735500L;
@QuerySqlField(index = true)
private String itemCode;
@QuerySqlField
private String areaCode;
@QuerySqlField
private String zoneCode;
@QuerySqlField
private Long demand;
@QuerySqlField
private Long inventory;
@QuerySqlField
private Double doi;
@QuerySqlField
private Long qtyToReachDoi;
}
存储库:
@Repository
@RepositoryConfig(cacheName = "itemCache")
public interface IgniteItemRepository extends IgniteRepository<Item,String> {
String queryForItemsWithDemandGT10 = "select * from item_cache i where i.demand>10";
@Query(value = queryForItemsWithDemandGT10)
public List<Item> getItemWithDemandGT10();
}
ServiceImpl:
@Service
public class IgniteItemServiceImpl implements IgniteItemService {
@Autowired
IgniteItemRepository repo;
@Override
public Mono<Item> saveBulkItemToCache(MultipartFile file) {
return Mono.create(consumer -> {
ObjectMapper objectMapper = new ObjectMapper();
try {
InputStream in = file.getInputStream();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
List<Item> itemList = objectMapper.readValue( in, new TypeReference<List<Item>>(){});
itemList.forEach(e->repo.save(String.valueOf(Math.random()),e));
} catch (Exception ex ) {
ex.printStackTrace();
}
});
}
@Override
public List<Item> viewItemList() {
List<Item> itemList = new ArrayList<>();
repo.findAll().forEach(e->itemList.add(e));
return itemList;
}
@Override
public List<Item> viewItemWithDemand() {
return repo.getItemWithDemandGT10();
}
}
点燃配置:
@Configuration
@EnableIgniteRepositories
public class ApacheIgniteConfiguration {
@Bean
public Ignite igniteInstance(@Autowired IgniteConfiguration igniteConfiguration) {
igniteConfiguration.setAutoActivationEnabled(true);
igniteConfiguration.setActiveOnStart(true);
Ignite ignite = Ignition.getOrStart(igniteConfiguration);
ignite.active(true);
return ignite;
}
@Bean(name = "igniteConfiguration")
public IgniteConfiguration igniteConfiguration() {
IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
igniteConfiguration.setIgniteInstanceName("igniteTest");
igniteConfiguration.setClientMode(false);
igniteConfiguration.setPeerClassLoadingEnabled(true); //to allow any client to put node on cluster
igniteConfiguration.setLocalHost("127.0.0.1");
TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));
tcpDiscoverySpi.setIpFinder(ipFinder);
tcpDiscoverySpi.setLocalPort(47500);
// Changing local port range. This is an optional action.
tcpDiscoverySpi.setLocalPortRange(9);
//tcpDiscoverySpi.setLocalAddress("localhost");
igniteConfiguration.setDiscoverySpi(tcpDiscoverySpi);
TcpCommunicationSpi communicationSpi = new TcpCommunicationSpi();
communicationSpi.setLocalAddress("localhost");
communicationSpi.setLocalPort(48100);
communicationSpi.setSlowClientQueueLimit(1000);
igniteConfiguration.setCommunicationSpi(communicationSpi);
DataStorageConfiguration storageConfiguration = new DataStorageConfiguration();
DataRegionConfiguration regionConfiguration = new DataRegionConfiguration();
regionConfiguration.setPersistenceEnabled(true);
regionConfiguration.setName("igniteRegion");
storageConfiguration.setDefaultDataRegionConfiguration(regionConfiguration);
igniteConfiguration.setDataStorageConfiguration(storageConfiguration);
igniteConfiguration.setCacheConfiguration(cacheConfiguration());
return igniteConfiguration;
}
@Bean(name = "cacheConfiguration")
public CacheConfiguration[] cacheConfiguration() {
List<CacheConfiguration> cacheConfigurations = new ArrayList<>();
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cacheConfiguration.setCacheMode(CacheMode.REPLICATED);
cacheConfiguration.setName("employee");
cacheConfiguration.setWriteThrough(false);
cacheConfiguration.setReadThrough(false);
cacheConfiguration.setWriteBehindEnabled(false);
cacheConfiguration.setBackups(1);
cacheConfiguration.setStatisticsEnabled(true);
cacheConfiguration.setIndexedTypes(Long.class,Employee.class);
CacheConfiguration cacheConfiguration1 = new CacheConfiguration();
cacheConfiguration1.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cacheConfiguration1.setCacheMode(CacheMode.REPLICATED);
cacheConfiguration1.setName("itemCache");
cacheConfiguration1.setWriteThrough(false);
cacheConfiguration1.setReadThrough(false);
cacheConfiguration1.setWriteBehindEnabled(false);
cacheConfiguration1.setBackups(1);
cacheConfiguration1.setStatisticsEnabled(true);
cacheConfiguration.setIndexedTypes(String.class,Item.class);
cacheConfigurations.add(cacheConfiguration);
cacheConfigurations.add(cacheConfiguration1);
return cacheConfigurations.toArray(new CacheConfiguration[cacheConfigurations.size()]);
}
}
错误:
org.apache.ignite.IgniteException: Failed to find SQL table for type: Item
at org.apache.ignite.internal.processors.query.GridQueryProcessor.typeName(GridQueryProcessor.java:2898) ~[ignite-core-2.8.1.jar:2.8.1]
at org.apache.ignite.internal.processors.query.GridQueryProcessor.querySql(GridQueryProcessor.java:2548) ~[ignite-core-2.8.1.jar:2.8.1]
at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.query(IgniteCacheProxyImpl.java:799) ~[ignite-core-2.8.1.jar:2.8.1]
at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.query(GatewayProtectedCacheProxy.java:412) ~[ignite-core-2.8.1.jar:2.8.1]
at org.apache.ignite.springdata22.repository.query.IgniteRepositoryQuery.execute(IgniteRepositoryQuery.java:121) ~[ignite-spring-data_2.2-2.8.1.jar:2.8.1]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137) ~[spring-data-commons-2.4.6.jar:2.4.6]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121) ~[spring-data-commons-2.4.6.jar:2.4.6]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152) ~[spring-data-commons-2.4.6.jar:2.4.6]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:131) ~[spring-data-commons-2.4.6.jar:2.4.6]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.5.jar:5.3.5]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.5.jar:5.3.5]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.5.jar:5.3.5]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.5.jar:5.3.5]
at com.sun.proxy.$Proxy84.getItemWithDemandGT10(Unknown Source) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.5.jar:5.3.5]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.5.jar:5.3.5]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.5.jar:5.3.5]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-5.3.5.jar:5.3.5]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.5.jar:5.3.5]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.5.jar:5.3.5]
at com.sun.proxy.$Proxy84.getItemWithDemandGT10(Unknown Source) ~[na:na]
at com.example.ignite.service.impl.IgniteItemServiceImpl.viewItemWithDemand(IgniteItemServiceImpl.java:48) ~[classes/:na]
at com.example.ignite.controller.IgniteItemController.viewItemWithDemand(IgniteItemController.java:33) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197) ~[spring-web-5.3.5.jar:5.3.5]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141) ~[spring-web-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1060) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.5.jar:5.3.5]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:645) ~[javax.servlet-api-4.0.1.jar:4.0.1]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.5.jar:5.3.5]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750) ~[javax.servlet-api-4.0.1.jar:4.0.1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.5.jar:5.3.5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.5.jar:5.3.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.5.jar:5.3.5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.5.jar:5.3.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.5.jar:5.3.5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.5.jar:5.3.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) [tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) [tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) [tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) [tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) [tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707) [tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.44.jar:9.0.44]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_171]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.44.jar:9.0.44]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]
【问题讨论】:
标签: java spring-boot caching spring-data ignite