【问题标题】:JPA repository .save in Netty server channelInitializer handler not workingNetty服务器channelInitializer处理程序中的JPA存储库.save不起作用
【发布时间】:2021-12-12 15:34:51
【问题描述】:

我已经在 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> {

}

The folder structure 我收到的异常

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)

在记录器中,我收到“保存前”,但之后什么都没有,应用程序堆栈。

感谢您的帮助

【问题讨论】:

  • 应用程序堆栈是什么意思...请显示异常...
  • 既不显示异常也不前进。
  • 你的 NettyServerHandler 类上面有@component,还在你的 log.info("beforeSave") 之前打印 testrepo,我想知道它是否为 null
  • 我在 NettyServerHandler 类的顶部添加了@component,但没有任何改变。 testrepo 的 print 为 null。
  • 你使用什么版本的spring-boot?你在使用 ComponentScan 吗?

标签: java spring-boot netty


【解决方案1】:

我拿走了您的代码并删除了所有(新)和所有(构造函数)。最好让 Springboot 为你自动装配一切:

注意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

【讨论】:

    【解决方案2】:

    尝试使用spring-boot-starter-jdbc,你不会遇到这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 2013-09-30
      相关资源
      最近更新 更多