0

对不起我的英语不好。

第一次使用 Spring 4,我开始怀疑它是真的有帮助还是只是令人不安。当会话到期时,会在 36 到 60 秒之间重新连接。

使用:Spring-boot with Hibernate4 + JPA2 + HikariCP (pool) + Hibernate.spatial

我在瓶颈的这条线上加上了一个星号。

2014-07-08 17:59:14 DEBUG o.s.s.w.u.m.AntPathRequestMatcher:145 - Checking match of request : '/rest/restaurant/c1f15300-8bfc-496b-b90c-cf57596c8319/detail'; against '/rest/restaurant'
2014-07-08 17:59:14 DEBUG o.s.s.w.u.m.AntPathRequestMatcher:145 - Checking match of request : '/rest/restaurant/c1f15300-8bfc-496b-b90c-cf57596c8319/detail'; against '/rest/restaurant/**'
2014-07-08 17:59:14 DEBUG o.s.s.w.FilterChainProxy:180 - /rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail has an empty filter list
2014-07-08 17:59:14 DEBUG o.s.w.s.DispatcherServlet:838 - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/almocaqui/rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail]
2014-07-08 17:59:14 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:246 - Looking up handler method for path /rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail
2014-07-08 17:59:14 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:251 - Returning handler method [public com.snowmanlabs.almocaqui.domain.external.ExternalBasicRestaurant com.snowmanlabs.almocaqui.rest.controller.RestaurantRestController.getDetail(java.lang.String)]
2014-07-08 17:59:14 DEBUG o.s.b.f.s.DefaultListableBeanFactory:249 - Returning cached instance of singleton bean 'restaurantRestController'
2014-07-08 17:59:14 DEBUG o.s.w.s.DispatcherServlet:925 - Last-Modified value for [/almocaqui/rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail] is: -1
2014-07-08 17:59:14 DEBUG o.s.o.j.s.OpenEntityManagerInViewInterceptor:87 - Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2014-07-08 17:59:14 DEBUG o.s.b.f.s.DefaultListableBeanFactory:249 - Returning cached instance of singleton bean 'transactionManager'
2014-07-08 17:59:14 DEBUG o.s.o.j.JpaTransactionManager:334 - Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@1007b020] for JPA transaction
***2014-07-08 17:59:14 DEBUG o.s.o.j.JpaTransactionManager:367 - Creating new transaction with name [com.snowmanlabs.almocaqui.service.implement.RestaurantServiceImpl.getRestaurant]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
2014-07-08 17:59:48 DEBUG o.s.o.j.JpaTransactionManager:403 - Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@356f95be]
2014-07-08 17:59:49 DEBUG o.s.o.j.JpaTransactionManager:755 - Initiating transaction commit
2014-07-08 17:59:49 DEBUG o.s.o.j.JpaTransactionManager:510 - Committing JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@1007b020]
2014-07-08 17:59:49 DEBUG o.s.o.j.JpaTransactionManager:603 - Not closing pre-bound JPA EntityManager after transaction
2014-07-08 17:59:50 DEBUG o.s.w.s.m.m.a.RequestResponseBodyMethodProcessor:145 - Written [com.snowmanlabs.almocaqui.domain.external.ExternalBasicRestaurant@479caa5b] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@4a37a117]
2014-07-08 17:59:50 DEBUG o.s.w.s.DispatcherServlet:1012 - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2014-07-08 17:59:50 DEBUG o.s.o.j.s.OpenEntityManagerInViewInterceptor:112 - Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2014-07-08 17:59:50 DEBUG o.s.o.j.EntityManagerFactoryUtils:435 - Closing JPA EntityManager
2014-07-08 17:59:50 DEBUG o.s.w.s.DispatcherServlet:991 - Successfully completed request

PS:AWS中的这个问题,使得网站下线(超过了Internal hold的最大时间)


我的文件摘要:

*RestaurantRestController.java

@Controller
@RequestMapping(value = "/rest/restaurant")
public class RestaurantRestController {

    private final RestaurantService service;

    @Inject
    public RestaurantRestController(final RestaurantService service) {
        this.service = service;
    }
    
    
    @RequestMapping(value = "/{uuid}/detail", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public ExternalBasicRestaurant getDetail(@PathVariable("uuid") String uuid) {
        Restaurant restaurant = service.getRestaurant(uuid);

        ExternalBasicRestaurant external = createExternalBasicRestaurant(restaurant);
          
        return external;
    }
    @ExceptionHandler
    @ResponseStatus(HttpStatus.CONFLICT)
    public String handleUserAlreadyExistsException(UserAlreadyExistsException e) {
        return e.getMessage();
    }
}

*RestaurantServiceImpl.java

@Service
@Validated
public class RestaurantServiceImpl implements RestaurantService {

    private final RestaurantRepository repository;
    
    @Inject
    public RestaurantServiceImpl(final RestaurantRepository repository) {
        this.repository = repository;
    }
    
    @Override
    @Transactional(readOnly = true)
    public Restaurant getRestaurant(String uuid){
        Restaurant restaurant = repository.findOneByUUID(uuid);

        return restaurant;
    }
}

*RestaurantRepository.java

@Repository
public interface RestaurantRepository extends JpaRepository<Restaurant, Integer> {
}

*application.properties

# Spring
spring.profiles.active=dev

# Server
server.port=8080
server.sessionTimeout=30

# MVC
spring.view.prefix=/WEB-INF/jsp/
spring.view.suffix=.jsp

java.runtime.version=1.7

#DataSource
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://x.database.windows.net:1433;database=almocaqui;encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
spring.datasource.username=x
spring.datasource.password=x
spring.datasource.validationQuery=SELECT 1
spring.datasource.testOnBorrow=true
spring.datasource.poolPreparedStatements=true

# JPA
spring.jpa.database-platform=org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.autocommit=false
spring.data.jpa.repositories.enabled=true

# HikariCP
hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.minimumPoolSize=20
hibernate.hikari.maximumPoolSize=100
hibernate.hikari.idleTimeout=30

# Tomcat
tomcat.accessLogEnabled=false
tomcat.protocolHeader=x-forwarded-proto
tomcat.remoteIpHeader=x-forwarded-for
tomcat.backgroundProcessorDelay=10
server.tomcat.uri-encoding=UTF-8
server.session-timeout=10

*本地决赛:localhost:8080/rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail

4

2 回答 2

0

至少,您似乎使用的是旧版本的 HikariCP。不再支持引用的几个属性。我建议将 HikariCP 升级到 1.4.0。将您的 HikariCP 设置更改为以下推荐设置:

hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.minimumIdle=10
hibernate.hikari.maximumPoolSize=30
hibernate.hikari.idleTimeout=300000
hibernate.hikari.maxLifetime=600000
于 2014-07-09T14:20:28.620 回答
0

显然问题出在此处未共享的代码中。我在这篇文章中找到了答案:http: //zeroturnaround.com/rebellabs/how-to-use-jpa-correctly-to-avoid-complaints-of-a-slow-application/

许多人懒惰地认为作为 JSON 响应发送的最后一个对象。简单地删除了所有懒惰的东西,它看起来很有效。

我将重组我的代码。任何东西都回到这里。


编辑

问题是另一个。如果 AWS 中的服务器应用程序和 Azure 中的数据库,与数据库的重新连接速度很慢,但是 JPA 没有显示它。

留在所有 AWS 并获得“展示球”(正如巴西人所说,当然,曾经采取 7x1 并没有那么多.. 哈哈)。

于 2014-07-10T16:03:16.630 回答