我已经初始化了Netty服务器中的套接字通道,但我遇到了处理程序的问题,当我想通过JPA将从客户端接收到的数据保存到MySQL时,它无法保存。
package com.servernetty.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ServerApplication {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(ServerApplication.class, args);
}
}
@Service
public class ServerService {
private static final Logger logger = LoggerFactory.getLogger(ServerService.class);
private final TestRepo testRepo;
@Autowired
public ServerService(@Value("${hs.host}") String host, @Value("${hs.port}") int port, TestRepo testRepo) throws Exception {
this.testRepo = testRepo;
EventLoopGroup booGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap().
group(booGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.DEBUG))
.handler(new LoggingHandler(LogLevel.INFO))
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.localAddress("127.0.0.1", port).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new NettyServerHandler());
}
});
logger.info("You are here in message server port no: " + port);
ChannelFuture channel = bootstrap.bind(port).sync().channel().closeFuture().sync();
} finally {
logger.info("finallllllll: " + port);
booGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
}
public class NettyServerHandler extends ChannelInboundHandlerAdapter {
private final TestRepo testrepo;
public NettyServerHandler(TestRepo testrepo) {
this.testrepo = testrepo;
}
/**
* The message sent by the client will trigger
*/
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
TestModel trans = new TestModel();
trans.setId(11);
trans.setTestf("d11");
trans.setTransactionType("test");
log.info("before save");
try {
testrepo.save(trans);
} catch (Exception e) {
log.info("tttttttttttttt" + e.toString());
e.printStackTrace();
}
log.info("after save");
}
}
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
@Entity
@Table(name = "test", uniqueConstraints = @UniqueConstraint(columnNames = { "id" }, name = "TEST_UNIQUE_ID"))
public class TestModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", columnDefinition = "bigint unsigned")
private Integer id;
String testf;
@Column(name = "transaction_type")
String transactionType;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTestf() {
return testf;
}
public void setTestf(String testf) {
this.testf = testf;
}
public String getTransactionType() {
return transactionType;
}
public void setTransactionType(String transactionType) {
this.transactionType = transactionType;
}
}
import javax.transaction.Transactional;
import com.servernetty.server.model.TestModel;
import org.springframework.data.jpa.repository.JpaRepository;
public interface TestRepo extends JpaRepository<TestModel, Integer> {
}
文件夹结构是我收到的异常
java.lang.NullPointerException
at com.servernetty.server.handlers.NettyServerHandler.channelRead(NettyServerHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:829)
在logger中,我收到“保存前”消息,但之后什么都没有,应用程序堆叠。
谢谢你的帮助
尝试使用sping-boot-starter-jdbc,您将不会面临问题。
我拿走了你的代码并删除了所有(新)和所有(构造函数)。最好让Springboot Autowire为您提供一切:
注意ServerService和NettyServerHandler是如何实现的。
package com.example.socketchannel;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SocketchannelApplication {
public static void main(String[] args) {
SpringApplication.run(SocketchannelApplication.class, args);
}
}
package com.example.socketchannel.controller;
import com.example.socketchannel.service.NettyServerHandler;
import com.example.socketchannel.service.ServerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ServerController {
private static final Logger logger = LoggerFactory.getLogger(NettyServerHandler.class);
@Autowired
private ServerService serverService;
}
package com.example.socketchannel.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.*;
import io.netty.channel.socket.*;
import io.netty.channel.socket.nio.*;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
@Service
public class ServerService {
private static final Logger logger = LoggerFactory.getLogger(ServerService.class);
//You need to add hs.host to your properties
@Value("${hs.host:127:0.0.1}")
private String host;
//You need to add hs.port to your properties.
@Value("${hs.port:9090}")
private Integer port;
@Autowired
private NettyServerHandler nettyServerHandler;
@PostConstruct
private void init() {
EventLoopGroup booGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap().
group(booGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.DEBUG))
.handler(new LoggingHandler(LogLevel.INFO))
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.localAddress("127.0.0.1", port).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(nettyServerHandler);
}
});
logger.info("You are here in message server port no {}", port);
ChannelFuture channel = bootstrap.bind(port).sync().channel().closeFuture().sync();
} catch (InterruptedException e) {
logger.error("Encounterd Exception", e);
} finally {
logger.info("finallllllll: {} ", port);
booGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
}
package com.example.socketchannel.service;
import com.example.socketchannel.model.TestModel;
import com.example.socketchannel.repository.TestRepo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
@Service
public class NettyServerHandler extends ChannelInboundHandlerAdapter {
private static final Logger logger = LoggerFactory.getLogger(NettyServerHandler.class);
@Autowired
private TestRepo testRepo;
/**
* The message sent by the client will trigger
*/
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
TestModel trans = new TestModel();
trans.setId(11);
trans.setTestf("d11");
trans.setTransactionType("test");
logger.info("before save");
try {
testRepo.save(trans);
} catch (Exception e) {
logger.info("tttttttttttttt" + e.toString());
e.printStackTrace();
}
logger.info("after save");
}
}
package com.example.socketchannel.repository;
import com.example.socketchannel.model.TestModel;
import org.springframework.data.jpa.repository.JpaRepository;
public interface TestRepo extends JpaRepository<TestModel, Integer> {
}
package com.example.socketchannel.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
@Entity
@Table(name = "test", uniqueConstraints = @UniqueConstraint(columnNames = { "id" }, name = "TEST_UNIQUE_ID"))
public class TestModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", columnDefinition = "bigint unsigned")
private Integer id;
String testf;
@Column(name = "transaction_type")
String transactionType;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTestf() {
return testf;
}
public void setTestf(String testf) {
this.testf = testf;
}
public String getTransactionType() {
return transactionType;
}
public void setTransactionType(String transactionType) {
this.transactionType = transactionType;
}
}
<?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.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>socketchannel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>socketchannel</name>
<description>Demo project for Spring Boot</description>
<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-web</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>1.41.0</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>5.0.0.Alpha2</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Validating that the springboot context runs, if you do mvn clean install
package com.example.socketchannel;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SocketchannelApplicationTests {
@Test
void contextLoads() {
}
}
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building socketchannel 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://arm.lmera.ericsson.se/artifactory/proj-cv-dev-local/io/grpc/grpc-core/maven-metadata.xml
Downloading: https://arm.lmera.ericsson.se/artifactory/proj-cv-dev/io/grpc/grpc-core/maven-metadata.xml
Downloaded: https://arm.lmera.ericsson.se/artifactory/proj-cv-dev/io/grpc/grpc-core/maven-metadata.xml (0 B at 0.0 KB/sec)
Downloading: https://arm.lmera.ericsson.se/artifactory/proj-cv-dev-local/io/grpc/grpc-api/maven-metadata.xml
Downloading: https://arm.lmera.ericsson.se/artifactory/proj-cv-dev/io/grpc/grpc-api/maven-metadata.xml
Downloaded: https://arm.lmera.ericsson.se/artifactory/proj-cv-dev/io/grpc/grpc-api/maven-metadata.xml (2 KB at 10.5 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ socketchannel ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ socketchannel ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to C:\UCA-Development\cvc-clones\services\socketchannel\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ socketchannel ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\UCA-Development\cvc-clones\services\socketchannel\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ socketchannel ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\UCA-Development\cvc-clones\services\socketchannel\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ socketchannel ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.socketchannel.SocketchannelApplicationTests
14:01:36.120 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
14:01:36.140 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
14:01:36.228 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.example.socketchannel.SocketchannelApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
14:01:36.251 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.example.socketchannel.SocketchannelApplicationTests], using SpringBootContextLoader
14:01:36.260 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.socketchannel.SocketchannelApplicationTests]: class path resource [com/example/socketchannel/SocketchannelApplicationTests-context.xml] does not exist
14:01:36.261 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.socketchannel.SocketchannelApplicationTests]: class path resource [com/example/socketchannel/SocketchannelApplicationTestsContext.groovy] does not exist
14:01:36.261 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.example.socketchannel.SocketchannelApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
14:01:36.262 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.example.socketchannel.SocketchannelApplicationTests]: SocketchannelApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
14:01:36.351 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.example.socketchannel.SocketchannelApplicationTests]
14:01:36.542 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [C:\UCA-Development\cvc-clones\services\socketchannel\target\classes\com\example\socketchannel\SocketchannelApplication.class]
14:01:36.544 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.example.socketchannel.SocketchannelApplication for test class com.example.socketchannel.SocketchannelApplicationTests
14:01:36.788 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.example.socketchannel.SocketchannelApplicationTests]: using defaults.
14:01:36.788 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
14:01:36.823 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@38f116f6, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@5286c33a, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@6e6d5d29, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@5c530d1e, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@6c25e6c4, org.springframework.test.context.support.DirtiesContextTestExecutionListener@85e6769, org.springframework.test.context.transaction.TransactionalTestExecutionListener@c5ee75e, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@48a12036, org.springframework.test.context.event.EventPublishingTestExecutionListener@bf1ec20, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@70efb718, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@b70da4c, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@4a11eb84, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@4e858e0a, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@435fb7b5, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@4e70a728]
14:01:36.829 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@3f07b12c testClass = SocketchannelApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@4bd1f8dd testClass = SocketchannelApplicationTests, locations = '{}', classes = '{class com.example.socketchannel.SocketchannelApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@4bbf6d0e, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2415fc55, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@5e21e98f, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@7b993c65, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@6692b6c6, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@192d43ce], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
14:01:36.903 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.6)
2021-10-31 14:01:38.142 INFO 6128 --- [ main] c.e.s.SocketchannelApplicationTests : Starting SocketchannelApplicationTests using Java 11.0.7 on SE-00018098 with PID 6128 (started by ezsusmu in C:\UCA-Development\cvc-clones\services\socketchannel)
2021-10-31 14:01:38.150 INFO 6128 --- [ main] c.e.s.SocketchannelApplicationTests : No active profile set, falling back to default profiles: default
2021-10-31 14:01:41.285 INFO 6128 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-10-31 14:01:41.439 INFO 6128 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 135 ms. Found 1 JPA repository interfaces.
2021-10-31 14:01:46.495 INFO 6128 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-10-31 14:01:47.188 INFO 6128 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-10-31 14:01:47.567 INFO 6128 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-10-31 14:01:47.852 INFO 6128 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.32.Final
2021-10-31 14:01:48.528 INFO 6128 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-10-31 14:01:49.292 INFO 6128 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2021-10-31 14:01:51.596 INFO 6128 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-10-31 14:01:51.617 INFO 6128 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-10-31 14:01:53.868 INFO 6128 --- [ main] c.e.socketchannel.service.ServerService : You are here in message server port no 9090
2021-10-31 14:01:57.647 INFO 6128 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0x23fb4903] REGISTERED
2021-10-31 14:01:57.651 INFO 6128 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0x23fb4903] BIND: 0.0.0.0/0.0.0.0:9090
2021-10-31 14:01:57.655 INFO 6128 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0x23fb4903, L:/0:0:0:0:0:0:0:0:9090] ACTIVE
我正在使用Spring Batch和JPA处理一个批处理作业并执行更新。我正在使用默认的存储库实现。 并且我正在使用一个repository.save将修改后的对象保存在处理器中。而且,我没有在处理器或编写器中指定任何@Transactional注释。 下面是我的步骤,读取器和写入器配置:另外,我的config类是用EnableBatchProcessing注释的 在writer中,这就是我使用的
我有以下课程: DBEntity.java 使用者JAVA 用户服务。JAVA UserRepository.java
我有一个数据已经保存在我的数据库基于我的存储库和服务。我想保存另一个数据与邮递员只改变播放器id。但它不是创建一个新的实体数据。它更新现有的实体数据。我的问题是如何更新一个数据由我的服务当它找到一个现有的id。但当它找到一个新的id将保存一个新的数据到数据库。 这是我的回购: 这是我的服务:
我有一个在Netty中实现的服务器,它工作得很好,但现在我试图优化一个方面。 传入通道是多路复用的,即每个客户机进程都有许多线程,通过一个连接发送请求并读取响应到服务器。 谢谢, 安迪。
我有一个用例,我需要从一个Kafka主题中消费,做一些工作,生成另一个只有一次语义的Kafka主题,并保存到mongo数据库。看完文档后,我想kafka事务和mongo事务可以同步,但它们仍然是两个不同的事务。在下面的场景中,如果mongo提交失败,是否有方法回滚提交到主题并从消费者处重播的kafka记录。
我在使用JPA时遇到了一些困难。我没有得到任何异常,但我不能保存任何东西到数据库。我从Hibernate到Jpa,在那里一切都工作得很好。下面是我的文件 Application.Properties: 存储库: 服务: 我在提交表单时得到了200的响应,但在数据库中找不到数据