我正在将我的数据库管理从阻塞迁移到非阻塞(异步)api spring data r2dbc。但是我需要解决一些问题吗?
这是我尝试过的: 1.更改 R2DBC 和其他反应堆的依赖项。2.更改了该项目的springboot版本,您可以在我以前的项目中查看下面的pom.xml(但由于一些损坏的类,我已经删除了该项目)这很好用,但现在它不起作用。3. 多次更改 springframework 版本,我知道 R2DBC 仅适用于 5.2.0.RC2,但不知道它仍然无法正常工作。4.run maven clean install 但没什么大不了的。下面是我的代码。
这是我的 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 http://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.2.0.M6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>GamOneY</groupId>
<artifactId>gamoney.startup</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>GamOneY</name>
<description>PUBG_PC_AUTOMATION_MACHINE</description>
<properties>
<java.version>12</java.version>
<org.springframework.version>5.2.0.RC2</org.springframework.version>
<spring-cloud.version>Hoxton.M2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-util -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util</artifactId>
<version>9.0.26</version>
</dependency>
<!-- https://mvnrepository.com/artifact/tech.simter/simter-r2dbc-ext -->
<dependency>
<groupId>tech.simter</groupId>
<artifactId>simter-r2dbc-ext</artifactId>
<version>1.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.r2dbc/r2dbc-proxy -->
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-proxy</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.r2dbc/r2dbc-client -->
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-client</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot.experimental/spring-boot-autoconfigure-r2dbc -->
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-autoconfigure-r2dbc</artifactId>
<version>0.1.0.M1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-actuator-autoconfigure-r2dbc</artifactId>
<version>0.1.0.M1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot.experimental/spring-boot-starter-data-r2dbc -->
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
<version>0.1.0.M1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.github.mirromutth</groupId> -->
<!-- <artifactId>r2dbc-mysql</artifactId> -->
<!-- <version>${degraph-check.version}</version> -->
<!-- </dependency> -->
<!-- https://mvnrepository.com/artifact/io.r2dbc/r2dbc-h2 -->
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-proxy</artifactId>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-h2</artifactId>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-pool</artifactId>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-spi</artifactId>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-spi-parent</artifactId>
<version>0.8.0.M8</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.projectreactor/reactor-core -->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.projectreactor/reactor-test -->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <spring.framework.version>5.2.0.M2</spring.framework.version> -->
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>9.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.4</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20171018</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>com.github.mautini</groupId>
<artifactId>pubg-java</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.mautini</groupId>
<artifactId>pubg-java-utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency><!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.17</version>
</dependency> <!-- ALWAYS NECCESARY IF WE WANT TO USE JSP IN SPRING BOOT -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency> <!-- ALWAYS NECCESARY IF WE WANT TO USE JSP IN SPRING BOOT -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-r2dbc</artifactId>
<version>1.0.0.M2</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>io.r2dbc</groupId> -->
<!-- <artifactId>r2dbc-bom</artifactId> -->
<!-- <version>${r2dbc-releasetrain.version}</version> -->
<!-- <type>pom</type> -->
<!-- <scope>import</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spring-libs-snapshot</id>
<name>Spring Snapshot Repository</name>
<url>https://repo.spring.io/libs-snapshot</url>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-bom</artifactId>
<version>Arabba-M8</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<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.vaadin</groupId> -->
<!-- <artifactId>vaadin-bom</artifactId> -->
<!-- <version>${vaadin.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>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
现在这里是我的 springbootapplication 主类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.task.TaskExecutor;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.*;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
import CustomProperties.R2DBCProperties;
@EnableAsync //Asynchronisely running methods in seperate thread for handling concurrency by user requests
@EnableAutoConfiguration
@SpringBootApplication
@ComponentScan({"Phase3.Tournaments","Phase2.GamersDatabase","Phase4.Results","Phase5.BigGamesData.PUBG","ResultsRepositories","Phase6.ItsAllAboutMoney","Phase7.AwardsAreLove"})
@EnableTransactionManagement
@EnableScheduling
@EnableEurekaClient
@EnableR2dbcRepositories(basePackages="ResultRepositories")
@EntityScan("ResultsRepositories")
public class GamOneYApplication {
public static void main(String[] args) {
SpringApplication.run(GamOneYApplication.class, args);
System.out.println("I M STARTED");
}
@Bean(name="taskExecutor")
public TaskExecutor threadExecutor() { //BYDEFAULT SPRING WILL USE SIMPLEASYNCTASKEXECUTOR FOR RUNNY @ASYNC METHODS INSEPERATE THREAD WITH DEFAULT THREAD 1 PER REQUEST IF WE DONT PROVIDE THIS TASKEXECUTOR BEAN.
ThreadPoolTaskExecutor tps=new ThreadPoolTaskExecutor();
tps.setThreadNamePrefix("Another Thread");
tps.setCorePoolSize(10); //will bydefault create 10 threads in thread pool
tps.setQueueCapacity(100); //will hold pending tasts if threads are not available for the 11th request or access
tps.setMaxPoolSize(15); //if queue got full another 9 extra threads will be created
tps.initialize();
// tps.setThreadPriority(9);
return tps;
}
@Bean
public View jsonTemplate() {
MappingJackson2JsonView view = new MappingJackson2JsonView();
view.setPrettyPrint(true);
return view;
}
@Bean
@LoadBalanced
public RestTemplate restT() {
return new RestTemplate();
}
}
我使用我的 ReactiveCrudRepository(resultrepo1) 的类
package Phase4.Results;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.r2dbc.core.DatabaseClient;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import Phase3.Tournaments.*;
import Phase5.BigGamesData.PUBG.PubgStorage;
import ResultsRepositories.*;
import io.r2dbc.spi.ConnectionFactory;
@Component
public class MatchDataFetcher {
@Autowired
private ResultRepo1 repo1; //H2-DATABASE
@Autowired
private ResultRepo2 repo2;
@Autowired
protected DatabaseClient dc;
@Autowired
protected ConnectionFactory conn;
public List match1(HttpSession session,Class fetch,String entityName) { //Reusable functions
// Sort sort=
// repo.findAll(sort); WE WILL FIND OUT WHATS IS SORT CLASS SHORTLY...
// Map killers=new HashMap(); we will use it later if we needed
List l=(List) dc.select().from(fetch).fetch().all().collectList().cache().block();
System.out.println("heres list baby"+l);
Iterator it_mp4=l.iterator();
int i=0;
List<Match1Result> ordered1=(List<Match1Result>) repo1.getSortedResult().collectList().block();
//List<Match2Result> ordered2=(List<Match2Result>) repo2.getSortedResult().collectList().block();//for second match
while(it_mp4.hasNext()) {
// MatchP4 mp4=(MatchP4) it.next(); //FETCHING AND IDENTIFYING JOINED PLAYER GAME RESULT OF PARTICULAR TOURNAMENTS
MatchP4 mp4=(MatchP4) it_mp4.next();
if(session.getAttribute("user").equals((String)mp4.getUsername())) { //checking of result wheatha a player has joined or not
//System.out.println("Ordered==="+ordered1.get(i).getPubgname());
System.out.println(session.getAttribute("user")+"-----"+mp4.getUsername()+"==========YES");
return ordered1;
}
else {
System.out.println("not found");
}
i++;
}
return null;
// MapResult=={avatarname1=chocoTaco, avatarname0=chocoTaco, survived0=3698.114, survived1=3698.114, kills0=34, username1=nikki, kills1=34, username0=nikki}
}
}
我的结果repo1
package ResultsRepositories;
import java.io.Serializable;
import java.util.List;
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
import org.springframework.data.r2dbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@Repository
public interface ResultRepo1 extends ReactiveCrudRepository<Match1Result,Integer> {
@Transactional
//@Modifying(clearAutomatically=true,flushAutomatically=true)
@Query(value="UPDATE match1_result SET kills=$1,damage_dealt=$2 WHERE pubgname=$3")
public Mono<Match1Result> UpdateKills(int kills,float damage,String pubgname);
@Transactional
//@Modifying(clearAutomatically=true,flushAutomatically=true)
@Query(value="UPDATE match1_result SET kills=$1,survivetime=$2 WHERE pubgname=$3")
public int UpdateKillsMatch2(Integer kills,Double survivetime,String pubgname);
@Transactional
@Query(value="SELECT * from match1_result WHERE pubgname=$1")
public Mono<Match1Result> getLastKills(String pubgname);
//public List<T> getSortedKills();
@Transactional
@Query(value="SELECT * FROM match1_result ORDER BY kills,damagedealt DESC")
public Flux<Match1Result> getSortedResult();
}
这是我的整个过程。我第二次使用spring r2dbc,但不知道为什么我卡在这里,我确定这是一个依赖问题。我也在我的 github 帐户上发布了这个,但它仍然开放等待回复。请帮我解决这个问题。
这是我在应用程序启动时遇到的错误:
***************************
APPLICATION FAILED TO START
Description:
Field repo1 in Phase4.Results.MatchDataFetcher required a bean of type 'ResultsRepositories.ResultRepo1' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'ResultsRepositories.ResultRepo1' in your configuration.
我第二次使用spring r2dbc,但不知道为什么我卡在这里,我确定这是一个依赖问题。请帮我解决这个问题。