抱歉我的英文。
第一次使用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中的此问题导致网站停播(超过内部保留的最长时间)
* 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
*本地决赛: 本地主机:8080 /休息/餐厅/ C1F15300-8BFC-496B-B90C-CF57596C8319 /细节
答案 0 :(得分: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
答案 1 :(得分:0)
显然问题出现在这里没有分享的代码中。我在本文中找到了答案:http://zeroturnaround.com/rebellabs/how-to-use-jpa-correctly-to-avoid-complaints-of-a-slow-application/
很多人懒得将最后一个对象作为JSON响应发送。简单地删除所有懒惰,它看起来像它的工作。
我将重构我的代码。任何事都回到这里。
问题在于另一个问题。如果AWS中的服务器应用程序和Azure中的数据库,则重新连接数据库的速度很慢,但JPA没有显示它。
留在所有AWS中并得到了#34;显示球#34; (正如巴西人所说,当然曾经拿过7x1并不是那么多..大笑)。