Сброс соединения по одноранговой сети в приложении Spring Boot с Hibernate и Oracle - PullRequest
0 голосов
/ 25 октября 2018

Я получаю это исключение

  Caused by: java.sql.SQLException: An operation is being attempted on a closed connection.
   ------------------------ Cause of Close ---------------------------------
 java.io.IOException: Communication error with xxxxxxxxxx:9401[jdbc-1908517]
at cs.jdbc.driver.protocol.WireDecoder.processInput(WireDecoder.java:360)
at cs.jdbc.driver.protocol.ChannelConnection.processInput(ChannelConnection.java:371)
at cs.jdbc.driver.protocol.DataReader.run(DataReader.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
      Caused by: java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:197)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
at cs.jdbc.driver.protocol.ChannelConnection.read(ChannelConnection.java:376)
at cs.jdbc.driver.protocol.WireDecoder.processInput(WireDecoder.java:260)

... еще 5

                  at 


cs.jdbc.driver.CompositeConnection.getChannel(CompositeConnection.java:165)
at cs.jdbc.driver.CompositeConnection.prepareStatement(CompositeConnection.java:390)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
at com.sun.proxy.$Proxy120.prepareStatement(Unknown Source)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172)
... 104 common frames omitted

Я использую Spring Boot + Spring DATA + Hibernate / JPA.Через некоторое время я получаю это исключение.Но при перезапуске сервера приложение некоторое время остается работоспособным (когда снова возникает такое исключение).

Вот приложение.properties

    spring.datasource.url = jdbc:compositesw:dbapi@xxxxxxxxxxxxx:9401?domain=twccorp&dataSource=SFDC&autoReconnect=true
      spring.datasource.username = xxxx
   spring.datasource.password = xxxx
   spring.datasource.driverClassName = cs.jdbc.driver.CompositeDriver
   spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.OracleDialect
   spring.jpa.properties.hibernate.show_sql=true
   spring.jpa.properties.hibernate.use_sql_comments=true
   spring.jpa.properties.hibernate.format_sql=true


    spring.jpa.properties.hibernate.type=trace 

      spring.datasource.dbcp.test-while-idle=true
          spring.datasource.dbcp.validation-query=SELECT 1 from dual
      spring.datasource.dbcp.time-between-eviction-runs-millis=5000
    spring.datasource.dbcp.min-evictable-idle-time-millis=60000

     spring.datasource.test-while-idle=true
      spring.datasource.validation-query=SELECT 1 from dual
     spring.datasource.time-between-eviction-runs-millis=5000
         spring.datasource.min-evictable-idle-time-millis=60000

База данных - Oracle.

Вот реализация репозитория:

   @Repository
 public class AccountRepositoryCustomImpl implements AccountRepositoryCustom {

@PersistenceContext
private EntityManager em;

@Value("${recordLimit}")
private String recordLimit;

@Override
public List<AccountDatabase> searchForAccounts(Map<String, Object> map) {

    List<String> whereClause = new ArrayList<>();

    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("select ad from AccountDatabase ad ");

    for (String key : map.keySet()) {
        if (!key.equals("city") && !key.equalsIgnoreCase("address")) {
            whereClause.add(" ad." + key + " LIKE :" + key);
        }
    }

    queryBuilder.append(" where " + StringUtils.join(whereClause, " and "));

    if (map.containsKey("city")) {
        queryBuilder.append("(( ad.accountType = :accountType AND ad.billingCity LIKE :billingCity ) OR "
                + "( ad.accountType = :accountType2 AND ad.shippingCity LIKE :shippingCity ))");

    }

    if (map.containsKey("address")) {
        queryBuilder.append("(( ad.accountType = :accountType AND ad.billingStreet LIKE :billingStreet ) OR "
                + "( ad.accountType = :accountType2 AND ad.shippingStreet LIKE :shippingStreet ))");

    }

    Query jpaQuery = em.createQuery(queryBuilder.toString(), AccountDatabase.class);

    for (String key : map.keySet()) {
        if (!key.equals("city") && !key.equalsIgnoreCase("address")) {
            jpaQuery.setParameter(key, "%" + map.get(key) + "%");
        }
    }

    if (map.containsKey("address")) {
        jpaQuery.setParameter("accountType", "Billing Account");
        jpaQuery.setParameter("billingStreet", "%" + map.get("address") + "%");
        jpaQuery.setParameter("accountType2", "Service Location");
        jpaQuery.setParameter("shippingStreet", "%" + map.get("address") + "%");

    }

    if (map.containsKey("city")) {
        jpaQuery.setParameter("accountType", "Billing Account");
        jpaQuery.setParameter("billingCity", "%" + map.get("city") + "%");
        jpaQuery.setParameter("accountType2", "Service Location");
        jpaQuery.setParameter("shippingCity", "%" + map.get("city") + "%");

    }

    int limit = Integer.valueOf(recordLimit);
    List<AccountDatabase> list = jpaQuery.getResultList();
    if (list.size() > limit) {
        list = list.subList(0, limit);
    }

    em.close();
    return list;

}

}

Вот pom.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<artifactId>xxxxxxxx</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>

<parent>
    <groupId>xxxxxxxx</groupId>
    <artifactId>xxxxxxxx</artifactId>
    <version>0.0.2</version>
</parent>

<name>egateway-api-service</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java-version>1.8</java-version>
</properties>


<dependencies>

    <dependency>
        <groupId>some.group</groupId>
        <artifactId>non-maven-proj</artifactId>
        <version>1</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>






    <dependency>
        <groupId>org.ehcache</groupId>
        <artifactId>ehcache</artifactId>
    </dependency>

    <dependency>
        <groupId>javax.cache</groupId>
        <artifactId>cache-api</artifactId>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.4.0</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.4.0</version>
    </dependency>

    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-integration</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>

    </dependency>
    <!-- Hibernate 5.2.9 Final -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
    </dependency>
    <!-- Apache Commons DBCP -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-dbcp2</artifactId>
        <version>2.1.1</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Что я делаю не так?С уважением.

1 Ответ

0 голосов
/ 25 октября 2018

Это ответ удаленного сервера (или межсетевого экрана между ними).он заявляет, что не будет продолжать выполнение этого запроса.Это может быть брандмауэр или сбой рукопожатия SSL, проблема с прокси или даже неудачный запрос HTTP.Возможно, если вы не добавили правильные заголовки в запрос.

...