У меня есть простое приложение весенней загрузки, созданное на java 8 и развернутое как war to tomcat 8.5, в этом приложении у меня есть подключение к базе данных mysql, и все работает нормально при запуске, но после ошибки происходит с java .lang .IllegalStateException.
Я попробовал этот CommandLineRunner, чтобы проверить соединение с базой данных, и он отлично работает:
@Service
public class DBinit implements CommandLineRunner {
@Autowired
InfoService is;
@Autowired
AgentService as;
@Autowired
QuestionService qs;
@Override
public void run(String... args) throws Exception {
System.out.println("++++++++++++++++++++++++ DB init");
System.out.println("++++++++++++++++++++++++ "+is.getAll().size());
System.out.println("++++++++++++++++++++++++ "+qs.getAll().size());
System.out.println("++++++++++++++++++++++++ "+as.getAll().size());
}
это мой pom. xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>mada.regulator</groupId>
<artifactId>regulator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Mada_Regulator</name>
<description>wifi regulator from mada company</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency> -->
<!-- Web Jars -->
<!-- jQuery -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.4.1</version>
</dependency>
<!-- bootstrap -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.3.1</version>
</dependency>
<!-- font awesome -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>5.10.1</version>
</dependency>
<!-- popper -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>popper.js</artifactId>
<version>1.15.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
вот журнал [stdout.log]:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.5.RELEASE)
2020-03-17 20:30:19.245 INFO 20628 --- [com-startStop-1] mada.regulator.MadaRegulatorApplication : Starting MadaRegulatorApplication v0.0.1-SNAPSHOT on xjdz2.dailyrazor.com with PID 20628 (/home/madaelec/tomcat/webapps/regulator.mada-electronics.com/ROOT/WEB-INF/classes started by madaelec in /)
2020-03-17 20:30:19.268 INFO 20628 --- [com-startStop-1] mada.regulator.MadaRegulatorApplication : No active profile set, falling back to default profiles: default
2020-03-17 20:30:21.602 INFO 20628 --- [com-startStop-1] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-17 20:30:21.742 INFO 20628 --- [com-startStop-1] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 116ms. Found 3 JPA repository interfaces.
2020-03-17 20:30:22.481 INFO 20628 --- [com-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3136 ms
2020-03-17 20:30:23.012 INFO 20628 --- [com-startStop-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-03-17 20:30:23.585 INFO 20628 --- [com-startStop-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-03-17 20:30:23.793 INFO 20628 --- [com-startStop-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-03-17 20:30:24.177 INFO 20628 --- [com-startStop-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.12.Final
2020-03-17 20:30:25.170 INFO 20628 --- [com-startStop-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-03-17 20:30:25.648 INFO 20628 --- [com-startStop-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2020-03-17 20:30:28.477 INFO 20628 --- [com-startStop-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-03-17 20:30:28.511 INFO 20628 --- [com-startStop-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-03-17 20:30:30.082 WARN 20628 --- [com-startStop-1] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-03-17 20:30:30.552 INFO 20628 --- [com-startStop-1] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-17 20:30:31.438 INFO 20628 --- [com-startStop-1] mada.regulator.MadaRegulatorApplication : Started MadaRegulatorApplication in 14.13 seconds (JVM running for 25.931)
++++++++++++++++++++++++ DB init
++++++++++++++++++++++++ 1
++++++++++++++++++++++++ 0
++++++++++++++++++++++++ 0
и из журнала кота [catalina.log]:
2020-03-17 20:22:32,576 [regulator.mada-electronics.com-startStop-1] INFO org.apache.catalina.startup.HostConfig- Deployment of web application directory [/home/madaelec/tomcat/webapps/regulator.mada-electronics.com/ROOT] has finished in [22,776] ms
2020-03-17 20:22:32,585 [main] INFO org.apache.coyote.ajp.AjpNioProtocol- Starting ProtocolHandler ["ajp-nio-127.0.0.1-9558"]
2020-03-17 20:22:32,615 [main] INFO org.apache.catalina.startup.Catalina- Server startup in 23939 ms
2020-03-17 20:22:33,450 [mysql-cj-abandoned-connection-cleanup] INFO org.apache.catalina.loader.WebappClassLoaderBase- Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1305) [catalina.jar:8.5.20]
at org.apache.catalina.loader.WebappClassLoaderBase.getResource(WebappClassLoaderBase.java:986) [catalina.jar:8.5.20]
at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.checkThreadContextClassLoader(AbandonedConnectionCleanupThread.java:117) [mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:84) [mysql-connector-java-8.0.19.jar:8.0.19]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_11]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_11]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_11]
Примечание1: i есть другое приложение в том же коте, которое также подключается к mysql (другая схема) и использует другого пользователя, я пытался удалить его, но та же проблема все еще происходит. спасибо
Примечание 2: я сохранил только сущности и репозитории и удалил все остальное из приложения, но та же проблема
my application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/madaelec_regulator?characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=***
spring.datasource.password=***
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.format_sql=true
спасибо