1.跨域访问外部接口?
使用Nginx代理(详细参见:https://www.cnblogs.com/ZhaoHS/p/16594619.html);
合并部署,统一从后端访问第三方接口(合并部署详见:https://www.cnblogs.com/ZhaoHS/p/16601558.html);
后端响应头中加(Access-Control-Allow-Origin: *)*代表允许所有,或者指定具体IP端口or域名也行。
本来亲测前两种有效,第三种没试过。
2.idea中Java文件中jar包加载问题,如下图?
maven的配置文件settings.xml文件远程仓库配置awebide和aliyun,然后在项目目录下执行:mvn clean install。
3.idea构建代码报:AuthorityMapper.java:10:8
java: Internal error in the mapping processor: java.lang.NullPointerException
解决:Maven的版本与idea不匹配,一般降低/或升高maven版本简单不易引发其它问题。
4.spring-boot项目报:java.lang.NullPointerException at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
换Sun的jdk,或者给虚拟机加装字体:1)yum install fontconfig 2)fc-cache --force 3)重启项目
5.idea 启动代码调试时可以为spring boot添加启动参数?
1)打开启动配置,2)添加springboot启动的参数(有两个位置,选其一)
6.idea启动springboot项目报:UserMapper.java:14:8
java: Internal error in the mapping processor: java.lang.NullPointerException at org.mapstruct.ap.internal.processor
解决:Setting -->Build,Execution,Deployment -->Compiler -->User-local build加上参数:-Djps.track.ap.dependencies=false
7.DBvisualizer/idea连接mysql报错: No appropriate protocol
在URL中添加在数据库后面添加?createDatabaseIfNotExist=true&useSSL=false
如:jdbc:mysql://192.168.2.2:3306/test?createDatabaseIfNotExist=true&useSSL=false
8.SpringBoot项目在不同环境下的配置以及打包方式?
在服务启动加载的时候,服务器就会加载application.yml文件,然后通过配置去调用application-dev.yml文件,选择开发环境。当active: prod,那么服务在启动时,Spring就会调用application-prod.yml文件进入生产环境。详细参见:https://www.cnblogs.com/ZhaoHS/p/16594119.html
9.docker镜像中指定输出springboot项目日志?
ENTRYPOINT ["java", "-jar", "app.jar", "--spring.profiles.active=test", "--server.port=8080", "> /log/app.log"]
Dockerfile中执行语句中指定输出日志。或者项目中指定(未测试):https://blog.csdn.net/qq_40286424/article/details/119991090
10.SpringBoot项目在idea启动报(端口被占用):Application failed to start due to an exception
org.springframework.boot.web.embedded.tomcat.ConnectorStartFailedException: Connector configured to listen on port 80 failed to start
1)打开cmd 在CMD中输入命令:netstat -ano(注:以管理员的身份打开cmd)
2)在cmd中找到你启动的端口号,并记住端口号后面的PID
3)照样以管理员身份打开cmd,CMD中输入命令:taskkill /f /t /im 【PID】
11.解决java中Http请求头设置中文乱码问题?
String source = URLEncoder.encode("中文", "utf-8");
String result = URLDecoder.decode(source, "utf-8");
或者 headers.setContentType(MediaType.APPLICATION_JSON_UTF8);//尝试无效,最终使用第一种
12.idea启动SpringBoot项目报错:Error running BootApplication. Command line is too long. Shorten the command line via JAR manifest or via a classpath file and rerun.
12.启动报实体错误如: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Error parsing discriminator value......
解决方法(可能):
1.需要在实体类的主键上写上注解@Id标志位主键
2.更换成jdk1.8
3.加注解@Proxy(lazy = false)
4.实体名称冲突
13.SpringBoot启动报:Error creating bean with name 'sdkFeignClient' defined in class path resource ......
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
INFO - main - 1696 - N/A - ConfigService - ACF destroy., current host: 192.168.224.122
INFO - main - 1696 - N/A - RemoteConfigLongPollServiceFactory - Remove PollService successfully with key is [business-intelligence_null]
ERROR - main - 1696 - N/A - LoggingFailureAnalysisReporter -......
可能原因:
1.端口占用,2.缺少jar包,3.缺少注解:@EnableAsfRest(restTemplate =false)
14.API调用报:WARN - http-nio-9097-exec-1 - 8080 - N/A - SqlExceptionHelper - SQL Error: 0, SQLState: S0022
ERROR - http-nio-9097-exec-1 - 8080 - N/A - SqlExceptionHelper - Column 'select_month' not found.
ERROR - http-nio-9097-exec-1 - 8080 - N/A - OrderBIDomainService - get data with time exception
原因:自定义的jpa查询数据转entity使用有问题,不能自动转换,需要在server层根据实际类型手动转。
直接使用NativeQuery方式实现复杂查询,直观且便利,弊端在于无法返回自定义实体类。需要手动封装工具类来实现Object到目标对象的反射。
15.SpringBoot项目启动报:SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
注意:Intellij IDEA的版本,springboot的版本
请仔细检查pom.xml文件中的标签:parent、modelVersion、artifactId
16.SpringBoot项目启动报:Error creating bean with name 'fileController': Unsatisfied dependency expressed through field 'fileService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'upload-dir' in value "${upload-dir}"
解决方法:1.@Value("${upload-dir:}"),如此写给默认值
2.配置文件加上upload-dir: /root/web/uploadfile
3.注释or删除相关代码
未完待续......