问题1
org.apache.catalina.LifecycleException: An invalid Lifecycle transition was attempted ([before_stop]) for component
用不了反射,所以需要这个文件去
package org.wxy.example.sqlite.config;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import cn.hutool.core.util.ClassUtil;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
/**
* 反射将所有项目类扫描加入到服务, 大力出奇迹的操作,感觉不太合适,不过先让服务跑起来
*
* @author PC
*
*/
@Component
public class ClassReflectConfig {
static boolean begin = true;
// @Value("${scanclass}")
private Boolean scanclass=true;
@Autowired
private ThreadPoolTaskExecutor executorService;
@PostConstruct
public void init() {
if (scanclass) {
System.err.println("配置文件下 scanclass 开启了生成反射类");
} else {
System.err.println("配置文件下 scanclass 关闭了生成反射类");
}
synchronized (ClassReflectConfig.class) {
if (begin && scanclass) {
begin = false;
executorService.submit(() -> {
{
// 扫描系统第二级开始的包
String packageName = ClassReflectConfig.class.getPackageName();
String proPackageName = packageName.substring(0,
packageName.indexOf(".", packageName.indexOf(".") + 1));
// 可以在这个地方,添加除了服务以外其他的包,将会加入反射,以供graalvm生成配置
List<String> asList = Arrays.asList(proPackageName);
for (String spn : asList) {
try {
Set<Class<?>> doScan = ClassUtil.scanPackage(spn);
for (Class clazz : doScan) {
handlerClass(clazz);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
});
}
}
}
private void handlerClass(Class clazz) {
if (clazz.equals(ClassReflectConfig.class)) {
// 跳过自己,避免形成循环
return;
}
executorService.submit(() -> {
try {
System.err.println("反射注入:" + clazz.getName());
// 生成所有的构造器
Constructor[] declaredConstructors = clazz.getDeclaredConstructors();
// 找到无参构造器然后实例化
Constructor declaredConstructor = clazz.getDeclaredConstructor();
declaredConstructor.setAccessible(true);
Object newInstance = declaredConstructor.newInstance();
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
try {
// 实例化成功,那么调用一下
method.setAccessible(true);
// graalvm必须需要声明方法
method.invoke(newInstance);
} catch (Throwable e) {
}
}
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
try {
field.setAccessible(true);
field.getType();
String name = field.getName();
field.get(newInstance);
} catch (Throwable e) {
}
}
System.err.println("反射注入完成:" + clazz.getName());
} catch (Throwable e) {
}
});
}
}
之后报错信息
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqliteController': Unsatisfied dependency expressed through field 'personService': Error creating bean with name 'personService': Unsatisfied dependency expressed through field 'dao': Error creating bean with name 'personMapper': Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.aot.AutowiredFieldValueResolver.resolveValue(AutowiredFieldValueResolver.java:195) ~[na:na]
at org.springframework.beans.factory.aot.AutowiredFieldValueResolver.resolveObject(AutowiredFieldValueResolver.java:154) ~[na:na]
at org.springframework.beans.factory.aot.AutowiredFieldValueResolver.resolve(AutowiredFieldValueResolver.java:143) ~[na:na]
at org.wxy.example.sqlite.controllers.SqliteController__Autowiring.apply(SqliteController__Autowiring.java:14) ~[na:na]
at org.springframework.beans.factory.support.InstanceSupplier$1.get(InstanceSupplier.java:83) ~[na:na]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.obtainInstanceFromSupplier(DefaultListableBeanFactory.java:947) ~[mysqlandmybatis.exe:6.0.8]
在这里插入图片描述
问题2
无法读取外部 DTD ‘mybatis-3-mapper.dtd’, 因为 accessExternalDTD 属性设置的限制导致不允许 ‘http’ 访问。
允许对 ‘http’ 的访问:
如果你确定从 ‘http’ 地址下载 DTD 文件是安全的,可以配置解析器以允许对 ‘http’ 的访问。在 Java 中,可以使用以下代码:
System.setProperty("javax.xml.accessExternalDTD", "all");
问题3
exe文件闪退日志
用powerShell打开
问题4
说不支持http协议
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<buildArgs combine.children="append">
<buildArg>--enable-url-protocols=http</buildArg>
</buildArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>sonatype-oss-snapshots</id>
<name>Sonatype OSS Snapshots Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
问题5
暂不支持mybatis-plus