Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教下各位大佬 #8

Open
Hao-xy opened this issue Oct 31, 2022 · 6 comments
Open

请教下各位大佬 #8

Hao-xy opened this issue Oct 31, 2022 · 6 comments

Comments

@Hao-xy
Copy link

Hao-xy commented Oct 31, 2022

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'frontendCodeBuilder': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configuration' defined in class path resource [com/yupi/sqlfather/config/FreeMarkerConfigurationConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [freemarker.template.Configuration]: Factory method 'configuration' threw exception; nested exception is java.io.FileNotFoundException: src\main\resources\templates does not exist.
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:332) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) [spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) [spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) [spring-boot-2.7.2.jar:2.7.2]
at com.yupi.sqlfather.MainApplication.main(MainApplication.java:14) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_332]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_332]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_332]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_332]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.7.5.jar:2.7.5]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configuration' defined in class path resource [com/yupi/sqlfather/config/FreeMarkerConfigurationConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [freemarker.template.Configuration]: Factory method 'configuration' threw exception; nested exception is java.io.FileNotFoundException: src\main\resources\templates does not exist.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeanByName(AbstractAutowireCapableBeanFactory.java:479) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:550) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:520) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:673) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:237) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:329) ~[spring-context-5.3.22.jar:5.3.22]
... 22 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [freemarker.template.Configuration]: Factory method 'configuration' threw exception; nested exception is java.io.FileNotFoundException: src\main\resources\templates does not exist.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.22.jar:5.3.22]
... 38 common frames omitted
Caused by: java.io.FileNotFoundException: src\main\resources\templates does not exist.
at freemarker.cache.FileTemplateLoader$1.run(FileTemplateLoader.java:123) ~[freemarker-2.3.31.jar:2.3.31]
at freemarker.cache.FileTemplateLoader$1.run(FileTemplateLoader.java:119) ~[freemarker-2.3.31.jar:2.3.31]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_332]
at freemarker.cache.FileTemplateLoader.(FileTemplateLoader.java:119) ~[freemarker-2.3.31.jar:2.3.31]
at freemarker.cache.FileTemplateLoader.(FileTemplateLoader.java:98) ~[freemarker-2.3.31.jar:2.3.31]
at freemarker.template.Configuration.setDirectoryForTemplateLoading(Configuration.java:1571) ~[freemarker-2.3.31.jar:2.3.31]
at com.yupi.sqlfather.config.FreeMarkerConfigurationConfig.configuration(FreeMarkerConfigurationConfig.java:20) ~[classes/:na]
at com.yupi.sqlfather.config.FreeMarkerConfigurationConfig$$EnhancerBySpringCGLIB$$92bcbb8.CGLIB$configuration$0() ~[classes/:na]
at com.yupi.sqlfather.config.FreeMarkerConfigurationConfig$$EnhancerBySpringCGLIB$$92bcbb8$$FastClassBySpringCGLIB$$d2cdab7b.invoke() ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.22.jar:5.3.22]
at com.yupi.sqlfather.config.FreeMarkerConfigurationConfig$$EnhancerBySpringCGLIB$$92bcbb8.configuration() ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_332]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_332]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_332]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_332]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.22.jar:5.3.22]
... 39 common frames omitted

@KweilinFang
Copy link

w我也是遇见这样的问题,是哪个路径的问题,具体我也不知道怎么解决

@KweilinFang
Copy link

KweilinFang commented Nov 2, 2022 via email

@Bemege
Copy link

Bemege commented Nov 2, 2022

按照你的方式修改完之后似乎还是不太行 报错内容: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2022-11-02 15:25:24.203 ERROR 19852 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   :  *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

------------------ 原始邮件 ------------------ 发件人: "liyupi/sql-father-backend-public" @.>; 发送时间: 2022年11月2日(星期三) 中午1:56 @.>; @.@.>; 主题: Re: [liyupi/sql-father-backend-public] 请教下各位大佬 (Issue #8) pom.xml添加build静态文件的处理 src/main/resources /.xml /.properties /.ftl — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.>

我发现了 就算这样改在运行过程中还是会有问题,我现在更换一种读取模板的新方式 目前看来可行 我正在验证

@Bemege
Copy link

Bemege commented Nov 2, 2022

更换模板读取方式可行,已测试 :

https://sqlfather.xgeek.top/

  1. 删除 com.yupi.sqlfather.config.FreeMarkerConfigurationConfig 文件,不再手动去resources目录下去读取模板

  2. 在 application.yml 中添加配置 freemarker.template-loader-path=classpath:/templates/

  3. 全局搜索 private static Configuration configuration; 修改为 private static FreeMarkerConfigurer freeMarkerConfigurer;

  4. 上一步的静态对象注入的set方法中的对象也要修改
    image

  5. 全局搜索 configuration.getTemplate 替换为 freeMarkerConfigurer.getConfiguration().getTemplate

@Bemege
Copy link

Bemege commented Nov 2, 2022

按照你的方式修改完之后似乎还是不太行 报错内容: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2022-11-02 15:25:24.203 ERROR 19852 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   :  *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

------------------ 原始邮件 ------------------ 发件人: "liyupi/sql-father-backend-public" @.>; 发送时间: 2022年11月2日(星期三) 中午1:56 @.>; @.@.>; 主题: Re: [liyupi/sql-father-backend-public] 请教下各位大佬 (Issue #8) pom.xml添加build静态文件的处理 src/main/resources /.xml /.properties /.ftl — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.>

我更新了最新方法 可以参考一下

@Bemege Bemege mentioned this issue Nov 2, 2022
@zhaohaoyun
Copy link

问题的原因是加载模板目录方法错误,setDirectoryForTemplateLoading在IDE运行没问题,但是打包发布以后没办法从jar包直接加载文件路径
正确解决方法:
cfg.setDirectoryForTemplateLoading(new File("src/main/resources/templates"));
修改为
cfg.setClassForTemplateLoading(this.getClass(),"templates");

项目中只要修改两个地方
com.yupi.sqlfather.config.FreeMarkerConfigurationConfig
com.yupi.sqlfather.FreeMarkerTest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants