Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR unknown command config

在阿里云部署springboot项目发现异常。在测试服是正常的,正式服使用了aliyun的redis服务

异常:
Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR unknown command config

应该是阿里云对redis进行了限制

需要增加:
@Configuration
public class RedisConfig {
@Bean
public static ConfigureRedisAction configureRedisAction() {
return ConfigureRedisAction.NO_OP;
}
}

传base64png图片到AliyunOSS

使用场景是想做图片裁剪,直接传oss

基本步骤:
1,图片裁剪,产生base64字符串,略
2,base64转blob
3,blob添加到表单
4,ajax上传

具体:

/**
     * 将以base64的图片url数据转换为Blob
     * @param urlData
     *            用url方式表示的base64图片数据
     */
    function convertBase64UrlToBlob(urlData){
        var bytes=window.atob(urlData.split(',')[1]);        //去掉url的头,并转换为byte
        //处理异常,将ascii码小于0的转换为大于0
        var ab = new ArrayBuffer(bytes.length);
        var ia = new Uint8Array(ab);
        for (var i = 0; i < bytes.length; i++) {
            ia[i] = bytes.charCodeAt(i);
        }
        return new Blob( [ab] , {type : 'image/png'});
    }

3添加到表单:

 var formParam = new FormData();
formParam.append("file",convertBase64UrlToBlob(base64Codes));

4,ajax提交:

$.ajax({
            type: 'POST',
            url: host ,
            data:formParam ,
...

OSS需要额外增加授权:具体参考官方例子
额外传这些参数:

 formParam.append("key",g_object_name);
        formParam.append("policy",policyBase64);
        formParam.append("OSSAccessKeyId",accessid);
        formParam.append("success_action_status",'200');
        formParam.append("signature",signature);

phabricator 无法安装在阿里云rds上

phabricator 报如下错误
Replicating Master
Database host “[数据库地址]” is configured as a master, but is replicating another host. This is dangerous and can mangle or destroy data. Only replicas should be replicating. Stop replication on the host or reconfigure Phabricator.

然后发现原因是RDS自动做了主从备份,据说还是双向,而且无法关闭。
只能从程序下手了,搜索代码发现在

switch ($ref->getReplicaStatus()) {
      case PhabricatorDatabaseRef::REPLICATION_MASTER_REPLICA:
     break;<----新增的
        $message = pht(
          'Database host "%s" is configured as a master, but is replicating '.
          'another host. This is dangerous and can mangle or destroy data. '.
          'Only replicas should be replicating. Stop replication on the '.
          'host or reconfigure Phabricator.',
 $ref->getRefKey());

https://secure.phabricator.com/source/phabricator/browse/master/src/applications/config/check/PhabricatorDatabaseSetupCheck.php;326d5bf8004ece51fbb44146766f5ddf765f1159
这个文件的174行左右判断验证了

然后我在case后直接写了个break,绕过了验证,反正是可以用了

springboot 使用druid做连接池 sql统计不显示等问题

参考 http://www.tuicool.com/articles/QRRJz2J
就是网上50%的转载帖都没写需要自己写个
public DataSource dataSource(){}
方法。不写的结果是 application.properties中的连接池配置数据都没生效!

@Component
@ConfigurationProperties(prefix = "spring.datasource")
public class DruidConfig {
    private String url;

    private String username;

    private String password;

    private String driverClassName;

    private int initialSize;

    private int maxActive;

    private int minIdle;

    private int maxWait;

    private long timeBetweenEvictionRunsMillis;

    private long minEvictableIdleTimeMillis;

    private String validationQuery;

    private boolean testWhileIdle;

    private boolean testOnBorrow;

    private boolean testOnReturn;

    private boolean poolPreparedStatements;

    private int maxPoolPreparedStatementPerConnectionSize;

    private String filters;

    public DruidConfig() {
    }

    public DruidConfig(String url, String username, String password, String driverClassName, int initialSize, int maxActive, int minIdle, int maxWait, long timeBetweenEvictionRunsMillis, long minEvictableIdleTimeMillis, String validationQuery, boolean testWhileIdle, boolean testOnBorrow, boolean testOnReturn, boolean poolPreparedStatements, int maxPoolPreparedStatementPerConnectionSize, String filters) {
        this.url = url;
        this.username = username;
        this.password = password;
        this.driverClassName = driverClassName;
        this.initialSize = initialSize;
        this.maxActive = maxActive;
        this.minIdle = minIdle;
        this.maxWait = maxWait;
        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
        this.validationQuery = validationQuery;
        this.testWhileIdle = testWhileIdle;
        this.testOnBorrow = testOnBorrow;
        this.testOnReturn = testOnReturn;
        this.poolPreparedStatements = poolPreparedStatements;
        this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize;
        this.filters = filters;
    }

    @Bean
    @Primary
    public DataSource dataSource() throws Exception{
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUrl(this.url);
        druidDataSource.setUsername(this.username);
        druidDataSource.setPassword(this.password);
        druidDataSource.setDriverClassName(this.driverClassName);
        druidDataSource.setInitialSize(this.initialSize);
        druidDataSource.setMaxActive(this.maxActive);
        druidDataSource.setMinIdle(this.minIdle);
        druidDataSource.setMaxWait(this.maxWait);
        druidDataSource.setTimeBetweenEvictionRunsMillis(this.timeBetweenEvictionRunsMillis);
        druidDataSource.setMinEvictableIdleTimeMillis(this.minEvictableIdleTimeMillis);
        druidDataSource.setValidationQuery(this.validationQuery);
        druidDataSource.setTestWhileIdle(this.testWhileIdle);
        druidDataSource.setTestOnBorrow(this.testOnBorrow);
        druidDataSource.setTestOnReturn(this.testOnReturn);
        druidDataSource.setPoolPreparedStatements(this.poolPreparedStatements);
        druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(this.maxPoolPreparedStatementPerConnectionSize);
        druidDataSource.setFilters(this.filters);
        try {
            if(null != druidDataSource) {
                druidDataSource.setFilters("wall,stat");
                druidDataSource.setUseGlobalDataSourceStat(true);
                druidDataSource.init();
            }
        } catch (Exception e) {
            throw new RuntimeException("load datasource error, dbProperties is :", e);
        }

        return druidDataSource;
    }
...set get
}

主机重置造成的面登录验证失效REMOTE HOST IDENTIFICATION HAS CHANGED!

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
2b:2c:dd:99:a8:1f:a6:e2:b1:59:0d:5d:40:04:df:21.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:4
RSA host key for videoapi3 has changed and you have requested strict checking.
Host key verification failed.

videoapi3代表主机名
简单的解决办法 :
删除/root/.ssh/known_hosts 中对应的主机记录,重新用ssh连接下就可以了

cas post跳转错误问题,post验证后重定向为get

症状是get验证没问题,post的时候会回跳到带ticket的get地址,当然本地不支持get就产生错误了。

网上可能遇到的不多,有的回答比较坑,也可能跟我的不一致,比如
acceptAnyProxy true
redirectAfterValidation false
这个答案反正我这无效。

解决办法也比较简单,其实就是每个页面都需要带个ticket
post地址也需要,只要在表单action的地址中增加参数ticket就好了
比如原来post到 http://do.action 那么就改成 http://do.action?ticket=
就好了。

maven 提示 java.security.ProviderException: java.security.KeyException

提示如:

[ERROR] Plugin org.codehaus.mojo:build-helper-maven-plugin:1.9.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.codehaus.mojo:build-helper-maven-plugin:jar:1.9.1: Could not transfer artifact org.codehaus.mojo:build-helper-maven-plugin:pom:1.9.1 from/to central (https://repo.maven.apache.org/maven2): java.security.ProviderException: java.security.KeyException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

主要原因是因为源地址是https地址,然而当前系统版本比较老,不支持… 网上大多解决办法是做个代理或者用各种办法把https转成http.
也尝试用使用自安装的maven和把openjdk换成官方jdk然并卵.
最简单的办法就是更新下软件版本,我的是centos, yum update!
完美

spring mvc cannot reliably process ‘persist’ call

spring mvc cannot reliably process ‘persist’ call
spring mvc +jpa 出现了这个问题, 也根据网上加过 @PersistenceContext @Transactional 这些注解,都没啥效果.

我的解决方式, 根据配置文件
原来的
@Autowired
EntityManager entityManager;

改成了
@Autowired
private EntityManagerFactory entityManagerFactory;

之后使用的时候
entityManagerFactory.createEntityManager()
就成功了,但这种方法需要自己关闭下EntityManager

java 时区 CST

之前没关注过, 理解上系统时间是UTC+8,并且new Date()添加到数据库是对的就正常了。

但是:发现如果是录入时间 比如字符串 “2016-09-09 00:00:00” 那么转换成Date就变成了CST时间,这样再录入数据库就会错误。
会是 2016-09-09 00:00:00 CST

解决方法:修改数据库时区就好了