社区论坛小程序开发踩坑-后端篇

1 openId的获取方式

每个小程序对应的wechat用户都有一个唯一的用户标识,即openId。开放平台提供接口获取。

2 图片中QRCode检测方式

不同于扫码识别QRCode,直接从图片中检测QRCode比较困难。国外开源的比较好的工具有 zxing ,但是识别率较低。国内的ali/wechat的QRCode检测识别接口并未开放,暂未找到更好的解决方式。

3 nginx配置

前后端分离式开发,使用nginx解决跨越等问题。配置文件如下:

server{
        listen       443;
        server_name  ***; #域名
        charset utf-8;
        ssl on;
        ssl_certificate /data/ssl/***.crt; #nginx方式的https证书
        ssl_certificate_key /data/ssl/***.key; #nginx方式的https key
        location /api/ {
                proxy_pass http://127.0.0.1:7777/; #后端服务
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-Port $server_port;
        }
        location / {
                proxy_pass http://127.0.0.1:8080/; #前端服务端口(本项目使用http-server启动的前端项目)
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-Port $server_port;
        }
        location /picFile/ {
                alias /data/picFile/; #本地存储图片的路径,使用nginx代理
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
   }

4 springBoot的war包产物启动方式

是的你没看错,就是这么坑。产品经理需要这种方式,大致步骤如下:

4.1 修改pom文件

在pom文件中添加如下配置

<packaging>jar</packaging>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-tomcat</artifactId>
	<scope>provided</scope>
</dependency>
4.2 修改启动类

将注释的代码放开

/**
 * @author zmchen
 * Create Time : 2018/9/12
 */
@EnableTransactionManagement
@EnableSwagger2
@SpringBootApplication
@ServletComponentScan
public class TestApplication /*extends SpringBootServletInitializer*/{

    public static void main(String[] args) {
        SpringApplication.run(TestApplication.class, args);
    }

    @Bean
    public PropertiesFactoryBean configProperties() {
        PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        try {
            propertiesFactoryBean.setLocations(resolver.getResources("classpath*:config/application.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return propertiesFactoryBean;
    }

    // 如果需要使用tomcat容器启动项目,请将这一段注释与 类的  extends 代码解除注释
    /*@Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder springApplicationBuilder) {
        return springApplicationBuilder.sources(TestApplication.class);
    }*/
}
4.3 filter检查

【重点】

如果你的springboot程序里面使用了filter,filter中又恰好使用了@AutoWired注入了其他类的话,那么使用war包启动项目时下面这个坑要避免掉。 本项目有个token filter拦截器,里面注入了redisUtil。启动之后,redisUtil一直是null,原因如下: 拦截器加载的时间点在springcontext之前,所以在拦截器中注入自然为null。 解决办法:

if (null ==redisUtil){
                    BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
                    redisUtil = (RedisUtil) factory.getBean("redisUtil");
                }

转载于:https://my.oschina.net/chyblog/blog/2874170

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值