Проблема: < /strong>
Когда я запускаю приложение, браузер (Localhost: 8080) сохраняет чрезвычайно быстро. Если я прокомментирую зависимость весеннего сеанса, приложение работает нормально.
Вот что я сделал до сих пор:
- Добавленная пружина-сеанс-jdbc Зависимость
- @Enablejdbchttpsession (maxinactiveintervalinseconds = 60 )
- Создал требуемые таблицы (, spring_session_attributes )
Код: Выделить всё
SPRING_SESSION - Проверенные записи сеанса создаются в db
- set spring.session.store-type = jdbc и и server.servlet.session.timeout = 1m
- отключен spring.session.jdbc.cleanup-cron
import org.springframework.context.annotation.Configuration;
import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession;
@Configuration
@EnableJdbcHttpSession(maxInactiveIntervalInSeconds = 60) // 1 minute for now
public class SessionConfig {
}
< /code>
application.properties:
# MySQL connection
spring.datasource.url=jdbc:mysql://localhost:3306/session
spring.datasource.username=root
spring.datasource.password=MyPassword
# Optional Hibernate tuning
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
# Session timeout (server-managed, complements JDBC)
server.servlet.session.timeout=1m
# Disable aggressive cleanup for now
spring.session.jdbc.cleanup-cron=0 */30 * * * * # every 30 mins
< /code>
mainview.java:
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.Route;
import org.springframework.beans.factory.annotation.Autowired;
import com.vaadin.flow.component.UI;
@Route("")
public class MainView extends VerticalLayout {
private final PersonRepository personRepository;
private final Grid grid = new Grid(Person.class);
public MainView(@Autowired PersonRepository personRepository) {
UI.getCurrent().setPollInterval(10000); // 10 seconds
this.personRepository = personRepository;
TextField firstNameField = new TextField("First Name");
TextField lastNameField = new TextField("Last Name");
Button addButton = new Button("Add", event -> {
Person person = new Person(firstNameField.getValue(), lastNameField.getValue());
personRepository.save(person);
updateGrid();
firstNameField.clear();
lastNameField.clear();
});
add(firstNameField, lastNameField, addButton, grid);
grid.setColumns("firstName", "lastName");
updateGrid();
}
private void updateGrid() {
grid.setItems(personRepository.findAll());
}
}
< /code>
Почему Ваадин продолжает освежать при включении пружинного сеанса?>
Подробнее здесь: https://stackoverflow.com/questions/796 ... ssion-jdbc