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

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

swagger+spring+junit冲突

swagger +spring+junit冲突
junit的测试跑不起来,主要原因是引用的注解造成的:

@Configuration
@EnableWebMvc
@EnableSwagger2
@ComponentScan(basePackages ={"xx"})
public class SwaggerConfig {
...
}

我的解决办法是把swaper配置文件分离出来,junit不调用.
原先配置文件只有默认的两个:
/WEB-INF/spring-servlet.xml
/WEB-INF/applicationContext.xml
修改后增加一个
/WEB-INF/spring-swagger.xml

并改成在web.xml导入配置文件

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
    /WEB-INF/spring-servlet.xml
    /WEB-INF/applicationContext.xml
    /WEB-INF/spring-swagger.xml
  </param-value>
</context-param>

参考:http://stackoverflow.com/questions/7471544/unit-testing-spring-mvc-web-app-could-not-autowire-field-private-javax-servlet

编译安装php56 线程安全要加装pthread

wget http://cn2.php.net/get/php-5.6.22.tar.gz/from/this/mirror

tar zxvf php-5.6.22.tar.gz

cd php-5.6.22

./configure --prefix=/usr/local/php5622 --enable-maintainer-zts --with-config-file-path=/usr/local/php5622/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-opcache --enable-mbstring --enable-soap --enable-zip --enable-bcmath--with-openssl --with-zlib --with-curl --with-gd --with-zlib-dir=/usr/lib--with-png-dir=/usr/lib --with-jpeg-dir=/usr/lib --with-mhash--with-apxs2=/usr/local/apache/bin/apxs

make
make install

添加软连接

添加 php-fpm用户
adduser php-fpm
groupadd www

php-fpm
复制默认配置文件
cp /usr/local/php5622/etc/php-fpm.conf.default /usr/local/php5622/etc/php-fpm.conf

cp /usr/local/src/php-5.6.22/php.ini-production /usr/local/php5622/etc/php.ini

增加启动脚本
http://coder.weisiliang.com/co_index.action?coid=38

增加memcache支持

http://pecl.php.net/package/memcache
wget http://pecl.php.net/get/memcache-3.0.8.tgz
tar zxvf memcache-3.0.8.tgz
cd memcache-3.0.8
phpize56
./configure --with-php-config=/usr/local/php5622/bin/php-config
make
make install

libmemcached
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar zxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure --prefix=/usr/local/libmemcached
make
make install

memcached php ext
wget http://pecl.php.net/get/memcached-2.2.0.tgz
tar zxvf memcached-2.2.0.tgz
cd memcached-2.2.0
phpize56
./configure --with-php-config=/usr/local/php5622/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached-sasl
make
make install