1.react打包
进入到my-app(项目文件夹)目录下, npm run build即可
2.打包后点击index.html是空白页
package.json最下面加上homepage就行,然后重新build
"homepage":"."
3.打包后的build文件夹里的文件放在哪里
4.index.html在springboot里打开又白页或报错了
在application.properties里添加如下代码
spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html
spring.mvc.static-path-pattern=/static/**
如果文件目录结构和我一样的话,继续在index.html里找包含/static的代码,在./static之前加一个../,这样就能顺利打开了
5.添加Spring Security后数据库数据连不上了
经过查询资料可知,Spring Security默认开启CSRF防护,如果是spring boot项目,在启用了@EnableWebSecurity注解后,CSRF保护就自动生效了。所以在默认配置下,即便已经登录了,页面中发起PATCH,POST,PUT和DELETE请求依然会被拒绝,并返回403,需要在请求接口的时候加入CSRF Token才行。
所以在配置中加上这句代码就一切正常了
http.csrf().disable();
6. 添加Spring Security后静态资源如图片,css,js等加载不了
这个问题花了一晚上才解决了,一直以为是自己路径出问题了,原来是拦截器的原因。
在SecurityConfig处加上你想要展示的资源的路径就行了
.antMatchers("/","/js/**","/css/**","/image/*","/fonts/**","/**/*.png","/**/*.jpg").permitAll()
如我要展示的图片是下面的asoul.jpg, 在html加入下面代码即可
<img alt=A-Soul src="../static/image/asoul.jpg" width="594" height="324" title="点击可跳转至ASOUL FAN">
<!-- 使用了thymeleaf,默认路径在templates下 -->
原文章
css加载不了的时候还发现了一个笨方法,直接在html<head>里加上<style type="text/css">
***(css代码)</style></head>就可以了
7.eclipse将springboot项目打成jar包
1.右击项目,选择Run As - Maven clean
2.右击项目,选择Run As - Maven instal
Tips:如果遇到SpringBoot Unable to find a @SpringBootConfiguration, you need to use @ContextConfigurationl,参考下面的文章
最后,项目地址是47.106.129.20:8080/,做的很简陋,但还是挺开心的