Spring boot wait_timeout
<p>I have a problem with error of <strong>wait_timeout:</strong></p>

<pre><code>Mon Aug 08 06:16:31 CEST 2016
There was an unexpected error (type=Internal Server Error, status=500).
PreparedStatementCallback; SQL [SELECT main_cat FROM category_mapping WHERE cat=?]; The last packet successfully received from the server was 246,098,167 milliseconds ago. The last packet sent successfully to the server was 246,098,260 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 246,098,167 milliseconds ago. The last packet sent successfully to the server was 246,098,260 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
</code></pre>

<p><strong>application.properties:</strong></p>

<pre><code>spring.datasource.url=jdbc:mysql://localhost/allek?autoReconnect=true
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.testWhileIdle = true
spring.datasource.timeBetweenEvictionRunsMillis = 3600000
spring.datasource.validationQuery = SELECT 1
</code></pre>

<p><strong>CategoryRepository.java:</strong></p>

<pre><code>package pl.bpo.archiwumallegro.repositories;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public class CategoryRepository {

    private JdbcTemplate jdbcTemplate;

    @Autowired
    public CategoryRepository(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public Optional&lt;Long&gt; findMainCategory(Long category) {
        String sql = "SELECT main_cat FROM category_mapping WHERE cat=?";
        return Optional.ofNullable(
                jdbcTemplate.queryForObject(sql, Long.class, category));
    }
}
</code></pre>

<p>What I can still make the connection to be all the time or to be automatically switched on?</p>