springboot+druid配置无效

使用druid-spring-boot-starter 提供的配置方法,运行之后应用不到druid连接处,而是默认的HikariPool

pom.xml

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.druid</groupId>
    <artifactId>druid</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>druid</name>
    <description>测试</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.10</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

运行的类


package com.druid;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages="com.alibaba.druid.spring.boot")
public class DruidApplication {

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

8个回答

参考 配置进行详细的对比:https://blog.csdn.net/u010513756/article/details/80235876

控制台一直都打印是:

 Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]

application:

# 只有下面三个是必填项(使用内嵌数据库的话这三个也可以不用填,会使用默认配置),其他配置不是必须的
spring.datasource.url=jdbc:h2:file:./demo-db
spring.datasource.username=sa
spring.datasource.password=sa
# driver-class-name 非必填可根据url推断
spring.datasource.driver-class-name=org.h2.Driver

#Druid 数据源配置,继承spring.datasource.* 配置,相同则覆盖
spring.datasource.druid.initial-size=2
spring.datasource.druid.max-active=30
spring.datasource.druid.min-idle=2
spring.datasource.druid.max-wait=1234
spring.datasource.druid.pool-prepared-statements=true
spring.datasource.druid.max-pool-prepared-statement-per-connection-size=5
#spring.datasource.druid.max-open-prepared-statements= #等价于上面的max-pool-prepared-statement-per-connection-size
spring.datasource.druid.validation-query=select 1
spring.datasource.druid.validation-query-timeout=1
spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.test-on-return=true
spring.datasource.druid.test-while-idle=true
spring.datasource.druid.time-between-eviction-runs-millis=10000
spring.datasource.druid.min-evictable-idle-time-millis=30001
spring.datasource.druid.async-close-connection-enable=true


spring.datasource.druid.aop-patterns=com.alibaba.druid.spring.boot.demo.service.*

# 自定义StatFilter 配置 其他 Filter 不再演示
spring.datasource.druid.filter.stat.db-type=h2
spring.datasource.druid.filter.stat.log-slow-sql=true
spring.datasource.druid.filter.stat.slow-sql-millis=2000

# JPA
spring.jpa.show-sql= true
spring.jpa.hibernate.ddl-auto=create-drop

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource, 加上这一句试试。

xiaohua914
xiaohua914 新版本已经不支持这样了
大约 2 年之前 回复

 添加hibernate依赖,mysql驱动,druid依赖。这里hibernate,mysql并不需要选择版本,添加parent依赖自动为你寻找对应的版本。
复制代码
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.jon-spring
jon-spring-boot
0.0.1-SNAPSHOT

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.0.BUILD-SNAPSHOT</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-redis</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-solr</artifactId>
    </dependency> -->

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.0.20</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

    <!-- <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
    </dependency>

    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
    </dependency>

    <dependency>
        <groupId>net.sf.dozer</groupId>
        <artifactId>dozer</artifactId>
        <version>5.3.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency> -->
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <encoding>UTF-8</encoding>
                <compilerArguments>
                    <extdirs>src/main/webapp/WEB-INF/lib</extdirs>
                </compilerArguments>
            </configuration>
        </plugin>
    </plugins>
</build>

<!-- Add Spring repositories -->
<!-- (you don't need this if you are using a .RELEASE version) -->
<repositories>
    <repository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <url>http://repo.spring.io/milestone</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/snapshot</url>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <url>http://repo.spring.io/milestone</url>
    </pluginRepository>
</pluginRepositories>

复制代码

  由于springboot强调去XML配置文件,强化注解。druid注入时,使用注解。

复制代码
package hello.configuration;

import javax.sql.DataSource;

import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.alibaba.druid.pool.DruidDataSource;

@Configuration
@EnableTransactionManagement
public class DataBaseConfiguration implements EnvironmentAware {

private RelaxedPropertyResolver propertyResolver;

@Override
public void setEnvironment(Environment env) {
    this.propertyResolver = new RelaxedPropertyResolver(env, "spring.datasource.");
}

@Bean(destroyMethod = "close", initMethod = "init")
public DataSource writeDataSource() {
    System.out.println("注入druid!!!");

    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(propertyResolver.getProperty("url"));
    datasource.setDriverClassName(propertyResolver.getProperty("driver-class-name"));
    datasource.setUsername(propertyResolver.getProperty("username"));
    datasource.setPassword(propertyResolver.getProperty("password"));
    datasource.setInitialSize(Integer.valueOf(propertyResolver.getProperty("initialSize")));
    datasource.setMinIdle(Integer.valueOf(propertyResolver.getProperty("minIdle")));
    datasource.setMaxWait(Long.valueOf(propertyResolver.getProperty("maxWait")));
    datasource.setMaxActive(Integer.valueOf(propertyResolver.getProperty("maxActive")));
    datasource.setMinEvictableIdleTimeMillis(Long.valueOf(propertyResolver.getProperty("minEvictableIdleTimeMillis")));
    return datasource;
}

}

复制代码

  application.properties配置文件,springboot推荐使用YAML格式作为资源配置文件首选,博主懒,一直用properties文件。项目启动时,会自动读取。

复制代码
#spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://localhost:3306/stest?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
spring.datasource.username=root
spring.datasource.password=root123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

\u4E0B\u9762\u4E3A\u8FDE\u63A5\u6C60\u7684\u8865\u5145\u8BBE\u7F6E\uFF0C\u5E94\u7528\u5230\u4E0A\u9762\u6240\u6709\u6570\u636E\u6E90\u4E2D

\u521D\u59CB\u5316\u5927\u5C0F\uFF0C\u6700\u5C0F\uFF0C\u6700\u5927

spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20

\u914D\u7F6E\u83B7\u53D6\u8FDE\u63A5\u7B49\u5F85\u8D85\u65F6\u7684\u65F6\u95F4

spring.datasource.maxWait=60000

\u914D\u7F6E\u95F4\u9694\u591A\u4E45\u624D\u8FDB\u884C\u4E00\u6B21\u68C0\u6D4B\uFF0C\u68C0\u6D4B\u9700\u8981\u5173\u95ED\u7684\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u5355\u4F4D\u662F\u6BEB\u79D2

spring.datasource.timeBetweenEvictionRunsMillis=60000

\u914D\u7F6E\u4E00\u4E2A\u8FDE\u63A5\u5728\u6C60\u4E2D\u6700\u5C0F\u751F\u5B58\u7684\u65F6\u95F4\uFF0C\u5355\u4F4D\u662F\u6BEB\u79D2

spring.datasource.minEvictableIdleTimeMillis=300000

#\u5B89\u5168\u966A\u4F60
#security.user.name=admin
#security.user.password=admin

#tomcat\u542F\u52A8\u7AEF\u53E3\u597D
#server.port=8089

spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.properties.hibernate.show_sql=true

复制代码

  hibernate配置,为了适配原有项目,需要注入sessionfactory。

复制代码
package hello.hibernate;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.criterion.Criterion;

import hello.page.PageFinder;

/**

  • hibernate接口
  • @author chenlili *
  • @param
    */
    public interface IHibernateBaseDao {

    /**

    • 根据ID获取实体对象.
    • @param id
    • 记录ID
    • @return 实体对象 */ public T get(Serializable id);

    /**

    • 根据ID获取实体对象.
    • @param id
    • 记录ID
    • @return 实体对象 */ public T load(Serializable id);

    /**

    • 根据ID数组获取实体对象集合.
    • @param ids
    • ID对象数组
    • @return 实体对象集合 */ public List get(Serializable[] ids);

    /**

    • 根据属性名和属性值获取实体对象.
    • @param propertyName
    • 属性名称
    • @param value
    • 属性值
    • @return 实体对象 */ public T get(String propertyName, Object value);

    /**

    • 根据属性名和属性值获取实体对象集合.
    • @param propertyName
    • 属性名称
    • @param value
    • 属性值
    • @return 实体对象集合 */ public List getList(String propertyName, Object value);

    /**

    • @Title: getList
    • @Description: 根据属性名和属性值数组获取实体对象集合.
    • @param propertyName
    • @param values
    • @return
    • @throws
    • @date: 2015-1-9上午10:01:49 */ public List getList(String propertyName, Object[] values);

    /**

    • 获取所有实体对象集合.
    • @return 实体对象集合 */ public List getAll();

    /**

    • 获取所有实体对象总数.
    • @return 实体对象总数 */ public Long getTotalCount();

    /**

    • 根据属性名、修改前后属性值判断在数据库中是否唯一(若新修改的值与原来值相等则直接返回true).
    • @param propertyName
    • 属性名称
    • @param oldValue
    • 修改前的属性值
    • @param oldValue
    • 修改后的属性值
    • @return boolean */ public boolean isUnique(String propertyName, Object oldValue, Object newValue);

    /**

    • 根据属性名判断数据是否已存在.
    • @param propertyName
    • 属性名称
    • @param value
    • @return boolean */ public boolean isExist(String propertyName, Object value);

    /**

    • 保存实体对象.
    • @param entity
    • 对象
    • @return ID */ public Serializable save(T entity);

    /**

    • 更新实体对象.
    • @param entity
    • 对象 */ public void update(T entity);

    /**

    • 删除实体对象.
    • @param entity
    • 对象
    • @return */ public void delete(T entity);

    /**

    • 根据ID删除实体对象.
    • @param id
    • 记录ID */ public void delete(Serializable id);

    /**

    • 根据ID数组删除实体对象.
    • @param ids
    • ID数组 */ public void delete(Serializable[] ids);

    /**

    • @Title: delete
    • @Description: 根据指定属性名和值删除记录
    • @param propertyName
    • @param value
    • @throws
    • @date: 2015-4-2下午02:07:36 */ public void delete(String propertyName, Object value);

    public int delete(Map condition) throws Exception;

    /**

    • 清除某一对象.
    • @param object
    • 需要清除的对象 */ public void evict(Object object);

    public void flush();

    public void clear();

    /**

    • 保存或更新对象
    • @Title: saveOrUpdate
    • @param o
    • @return 返回保存的对象
    • @throws Exception
    • @throws
    • @date: 2015-12-17上午11:49:31 */ public T saveOrUpdate(T o);

    /**

    • 创建 Criteria
    • @Title: createCriteria
    • @param criterions
    • @return
    • @throws
    • @date: 2015-12-17下午01:29:46 */ public Criteria createCriteria(Criterion... criterions);

    /**

    • 取得Entity的Criteria对象,带排序字段与升降序字段.
    • @param orderBy
    • @param isAsc
    • @param criterions
    • @return */ public Criteria createCriteria(String orderBy, boolean isAsc, Criterion... criterions);

    /**

    • 获得所有并排序
    • @Title: getAllByOrder
    • @param orderBy
    • @param isAsc
    • @return
    • @throws */ public List getAllByOrder(String orderBy, boolean isAsc, boolean useCache);

    /**

    • 获得指定条数并排序
    • @Title: getLimitByOrder
    • @param orderBy
    • @param isAsc
    • @param limit
    • @return
    • @throws */ public List getLimitByOrder(String orderBy, boolean isAsc, int limit, boolean useCache);

    /**

    • 获得总条数
    • @Title: getRowCount
    • @param criteria
    • @return
    • @throws */ public int getRowCount(Criteria criteria);

    /**

    • @Title: getListByCriteria
    • @Description: 根据标准查询器,查询数据
    • @param criteria
    • @return
    • @throws */ public List getListByCriteria(Criteria criteria);

    /**

    • 从指定行查询指定条数据
    • @Title: getListByCriteria
    • @param criteria
    • @param fistResult
    • @param maxResult
    • @return
    • @throws */ public List getListByCriteria(Criteria criteria, int fistRow, int rowNum, boolean useCache);

    /**

    • 分页查询
    • @Title: pagedByCriteria
    • @param criteria
    • @param pageNo
    • @param pageSize
    • @return
    • @throws */ public PageFinder pagedByCriteria(Criteria criteria, int pageNo, int pageSize);

    /**

    • 创建hqlQuery
    • @Title: createQuery
    • @param hql
    • @param values
    • @return
    • @throws */ public Query createQuery(String hql, Object... values);

    /**

    • 创建hqlQuery
    • @Title: createQuery
    • @param hql
    • @param values
    • @return
    • @throws */ public Query createQuery(String hql, Map values);

    /**

    • 创建sqlQuery
    • @Title: createSQLQuery
    • @param sql
    • @param values
    • @return
    • @throws */ public SQLQuery createSQLQuery(String sql, Object... values);

    /**

    • 创建sqlQuery
    • @Title: createSQLQuery
    • @param sql
    • @param values
    • @return
    • @throws */ public Query createSQLQuery(String sql, Map values);

    /**

    • 通过HQL得到一个对象
    • @Title: getObjectByHql
    • @param hql
    • @param values
    • @return
    • @throws */ public T getObjectByHql(String hql, Map values);

    /**

    • 通过HQL得到一个对象
    • @Title: getObjectByHql
    • @param hql
    • @param values
    • @return */ public T getObjectByHql(String hql, Object... values);

    /**

    • 通过HQL得到查询列表
    • @Title: getListByHql
    • @param hql
    • @param values
    • @return
    • @throws */ public List getListByHql(String hql, Map values);

    /**

    • 通过HQL得到查询列表
    • @Title: getListByHql
    • @param hql
    • @param values
    • @return */ public List getListByHql(String hql, Object... values);

    /**

    • 通过HQL得到查询列表
    • @Title: getListByHql
    • @param hql
    • @param values
    • @param firstRow
    • @param maxNum
    • @return
    • @throws */ public List getListByHql(String hql, int firstRow, int maxNum, Map values);

    /**

    • 通过HQL得到查询列表
    • @Title: getListByHql
    • @param hql
    • @param firstRow
    • @param maxNum
    • @param values
    • @return */ public List getListByHql(String hql, int firstRow, int maxNum, Object... values);

    /**

    • 分页查询:通过HQL,HQL不要包含子查询
    • @Title: pagedByHQL
    • @param hql
    • @param toPage
    • @param pageSize
    • @param values
    • @return
    • @throws */ public PageFinder pagedByHQL(String hql, int toPage, int pageSize, Map values);

    /**

    • 分页查询:通过HQL,HQL不要包含子查询
    • @Title: pagedByHQL
    • @param hql
    • @param toPage
    • @param pageSize
    • @param values
    • @return */ public PageFinder pagedByHQL(String hql, int toPage, int pageSize, Object... values);

    /**

    • 定制数据列表查询
    • @Title: getListByHQL
    • @param datasql
    • @param values
    • @return
    • @throws */ @SuppressWarnings("rawtypes") public List getListByHQL(String datasql, Map values);

    /**

    • 定制数据列表查询
    • @Title: getListByHQL
    • @param datasql
    • @param firstRow
    • @param maxNum
    • @param values
    • @return
    • @throws */ @SuppressWarnings("rawtypes") public List getListByHQL(String datasql, int firstRow, int maxNum, Map values);

    /**

    • 分页定制数据查询
    • @Title: pagedByHQLtoObject
    • @param countHql
    • @param hql
    • @param toPage
    • @param pageSize
    • @param values
    • @return
    • @throws */ public PageFinder pagedObjectByHQL(String countHql, String hql, int toPage, int pageSize, Map values);

    /**

    • 通过SQL语句列表查询
    • @Title: getListBySQL
    • @param datasql
    • @param values
    • @return
    • @throws */ public List getListBySQL(String datasql, Map values);

    /**

    • 通过SQL语句列表查询
    • @Title: getListBySQL
    • @param datasql
    • @param firstRow
    • @param maxNum
    • @param values
    • @return
    • @throws */ public List getListBySQL(String datasql, int firstRow, int maxNum, Map values);

    /**

    • 通过SQL语句分页查询
    • @Title: pagedBySQL
    • @param countsql
    • @param datasql
    • @param toPage
    • @param pageSize
    • @param values
    • @return
    • @throws */ public PageFinder pagedObjectBySQL(String countsql, String datasql, int toPage, int pageSize, Map values);

}

复制代码

复制代码
package hello.hibernate.impl;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.NonUniqueResultException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.metadata.ClassMetadata;
import org.springframework.util.Assert;

import hello.hibernate.IHibernateBaseDao;
import hello.page.PageFinder;
import hello.utils.ReflectionUtils;

public class HibernateBaseDao implements IHibernateBaseDao {
private final Class entityClass;
@Resource
protected SessionFactory sessionFactory;

@SuppressWarnings("unchecked")
public HibernateBaseDao() {
    this.entityClass = ReflectionUtils.getSuperClassGenricType(this.getClass(), 0);
}

public T load(Serializable id) {
    Assert.notNull(id, "id is required");
    return (T) this.getSession().load(this.entityClass, id);
}
protected void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
}
protected Session getSession() {
    return this.sessionFactory.getCurrentSession();
}

public T get(Serializable id) {
    Assert.notNull(id, "id is required");
    return (T) this.getSession().get(this.entityClass, id);
}

@SuppressWarnings("unchecked")
public List<T> get(Serializable[] ids) {
    Assert.notEmpty(ids, "ids must not be empty");
    String hql = "from " + this.entityClass.getName() + " as model where model.id in(:ids)";
    return this.getSession().createQuery(hql).setParameterList("ids", ids).list();
}

@SuppressWarnings("unchecked")
public T get(String propertyName, Object value) {
    // Assert.hasText(propertyName, "propertyName must not be empty");
    // Assert.notNull(value, "value is required");
    if (value == null) {
        return null;
    }
    String hql = "from " + this.entityClass.getName() + " as model where model." + propertyName + " = ?";
    return (T) this.getSession().createQuery(hql).setParameter(0, value).uniqueResult();
}

@SuppressWarnings("unchecked")
public List<T> getList(String propertyName, Object value) {
    Assert.hasText(propertyName, "propertyName must not be empty");
    Assert.notNull(value, "value is required");
    String hql = "from " + this.entityClass.getName() + " as model where model." + propertyName + " = ?";
    return this.getSession().createQuery(hql).setParameter(0, value).list();
}

@SuppressWarnings("unchecked")
public List<T> getList(String propertyName, Object[] values) {
    Assert.hasText(propertyName, "propertyName must not be empty");
    Assert.notNull(values, "values is required");
    String hql = "from " + this.entityClass.getName() + " as model where model." + propertyName + " in(:values)";
    return this.getSession().createQuery(hql).setParameterList("values", values).list();
}

@SuppressWarnings("unchecked")
public List<T> getAll() {
    String hql = "from " + this.entityClass.getName();
    return this.getSession().createQuery(hql).list();
}


public Long getTotalCount() {
    String hql = "select count(*) from " + this.entityClass.getName();
    return (Long) this.getSession().createQuery(hql).uniqueResult();
}


public boolean isUnique(String propertyName, Object oldValue, Object newValue) {
    Assert.hasText(propertyName, "propertyName must not be empty");
    Assert.notNull(newValue, "newValue is required");
    if (newValue == oldValue || newValue.equals(oldValue)) {
        return true;
    }
    if (newValue instanceof String) {
        if (oldValue != null && StringUtils.equalsIgnoreCase((String) oldValue, (String) newValue)) {
            return true;
        }
    }
    T object = this.get(propertyName, newValue);
    return object == null;
}


public boolean isExist(String propertyName, Object value) {
    Assert.hasText(propertyName, "propertyName must not be empty");
    Assert.notNull(value, "value is required");
    T object = this.get(propertyName, value);
    return object != null;
}


public Serializable save(T entity) {
    Assert.notNull(entity, "entity is required");
    return this.getSession().save(entity);
}


public void update(T entity) {
    Assert.notNull(entity, "entity is required");
    this.getSession().update(entity);
}


public T saveOrUpdate(T o) {
    this.getSession().saveOrUpdate(o);
    return o;
}


public void delete(T entity) {
    Assert.notNull(entity, "entity is required");
    this.getSession().delete(entity);
}


public void delete(Serializable id) {
    Assert.notNull(id, "id is required");
    T entity = this.load(id);
    this.getSession().delete(entity);
}


public void delete(Serializable[] ids) {
    Assert.notEmpty(ids, "ids must not be empty");
    for (Serializable id : ids) {
        T entity = this.load(id);
        this.getSession().delete(entity);
    }
}


public void delete(String propertyName, Object value) {
    Assert.notNull(propertyName, "propertyName is required");
    Assert.notNull(value, "value is required");
    String hql = "delete from " + this.entityClass.getName() + " as model where model." + propertyName + " = ?";
    this.getSession().createQuery(hql).setParameter(0, value).executeUpdate();
}


public int delete(Map<String, Object> conditions) throws Exception {
    if (null == conditions || conditions.isEmpty()) {
        throw new Exception("No conditions!");
    }

    StringBuffer hql = new StringBuffer("delete from " + this.entityClass.getName() + " as model ");
    if (null != conditions && conditions.size() > 0) {
        hql.append(" where ");

        int i = 1;
        Set<String> keySet = conditions.keySet();
        for (String key : keySet) {
            Object value = conditions.get(key);
            if (i > 1) {
                hql.append(" AND ");
            }
            if (value instanceof Collection<?> || value instanceof Object[]) {
                hql.append(" model." + key + " IN(:" + key + ") ");
            } else {
                hql.append(" model." + key + " = :" + key + " ");
            }
            ++i;
        }
    }

    Query createQuery = this.getSession().createQuery(hql.toString());
    createQuery = this.setParameter(createQuery, conditions);
    return createQuery.executeUpdate();
}


public void evict(Object object) {
    Assert.notNull(object, "object is required");
    this.getSession().evict(object);
}


public void flush() {
    this.getSession().flush();
}


public void clear() {
    this.getSession().clear();
}


public Criteria createCriteria(Criterion... criterions) {
    Criteria criteria = this.getSession().createCriteria(this.entityClass);
    for (Criterion c : criterions) {
        criteria.add(c);
    }
    return criteria;
}


public Criteria createCriteria(String orderBy, boolean isAsc, Criterion... criterions) {
    Criteria criteria = this.createCriteria(criterions);
    if (isAsc) {
        criteria.addOrder(Order.asc(orderBy));
    } else {
        criteria.addOrder(Order.desc(orderBy));
    }

    return criteria;
}


public List<T> getAllByOrder(String orderBy, boolean isAsc, boolean useCache) {
    return this.getLimitByOrder(orderBy, isAsc, -1, useCache);
}

@SuppressWarnings("unchecked")
public List<T> getLimitByOrder(String orderBy, boolean isAsc, int limit, boolean useCache) {
    Assert.hasText(orderBy);

    Order order = isAsc ? Order.asc(orderBy) : Order.desc(orderBy);
    Criteria criteria = this.createCriteria();
    if (limit > 0) {
        criteria.setMaxResults(limit);
    }
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).addOrder(order).setCacheable(useCache);
    return criteria.list();
}


public int getRowCount(Criteria criteria) {
    criteria.setProjection(Projections.rowCount());
    Long totalRows = (Long) criteria.uniqueResult();
    return totalRows.intValue();
}

@SuppressWarnings("unchecked")
public List<T> getListByCriteria(Criteria criteria) {
    criteria = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

@SuppressWarnings("unchecked")
public List<T> getListByCriteria(Criteria criteria, int fistRow, int rowNum, boolean useCache) {
    criteria = criteria.setFirstResult(fistRow).setMaxResults(rowNum).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).setCacheable(useCache);
    return criteria.list();
}


public PageFinder<T> pagedByCriteria(Criteria criteria, int pageNo, int pageSize) {
    int totalRows = this.getRowCount(criteria);
    criteria.setProjection(null);
    if (totalRows < 1) {
        PageFinder<T> finder = new PageFinder<T>(pageNo, pageSize, totalRows);
        finder.setData(new ArrayList<T>());
        return finder;
    } else {
        PageFinder<T> finder = new PageFinder<T>(pageNo, pageSize, totalRows);
        List<T> list = this.getListByCriteria(criteria, finder.getStartOfPage(), finder.getPageSize(), false);
        finder.setData(list);
        return finder;
    }
}


public Query createQuery(String hql, Object... values) {
    Assert.hasText(hql, "sql 不能为空");
    Query query = this.getSession().createQuery(hql);
    if (values != null) {
        for (int i = 0; i < values.length; i++) {
            query.setParameter(i, values[i]);
        }
    }
    return query;
}


public Query createQuery(String hql, Map<String, ?> values) {
    Assert.hasText(hql, "sql 不能为空");
    Query query = this.createQuery(hql);
    if (values != null) {
        query = this.setParameter(query, values);
    }
    return query;
}

@SuppressWarnings("unchecked")
public T getObjectByHql(String hql, Map<String, Object> values) {
    Query query = this.createQuery(hql, values);
    return (T) query.uniqueResult();
}

@SuppressWarnings("unchecked")
public List<T> getListByHql(String hql, Map<String, Object> values) {
    Query query = this.createQuery(hql);
    query = this.setParameter(query, values);
    return query.list();
}

@SuppressWarnings("unchecked")
public List<T> getListByHql(String hql, int firstRow, int maxNum, Map<String, Object> values) {
    Query query = this.createQuery(hql);
    query = this.setParameter(query, values);
    query.setFirstResult(firstRow);
    query.setMaxResults(maxNum);
    return query.list();
}


public PageFinder<T> pagedByHQL(String hql, int toPage, int pageSize, Map<String, Object> values) {
    String countQueryString = " select count(*) " + this.removeSelect(this.removeOrders(hql));
    List<T> countlist = this.getListByHql(countQueryString, values);
    Long totalCount = (Long) countlist.get(0);

    if (totalCount.intValue() < 1) {
        return new PageFinder<T>(toPage, pageSize, totalCount.intValue());
    } else {
        final PageFinder<T> finder = new PageFinder<T>(toPage, pageSize, totalCount.intValue());
        List<T> list = this.getListByHql(hql, finder.getStartOfPage(), finder.getPageSize(), values);
        finder.setData(list);
        return finder;
    }
}

@SuppressWarnings("rawtypes")
public List getListByHQL(String datasql, Map<String, Object> values) {
    Query dataQuery = this.createQuery(datasql, values);
    return dataQuery.list();
}

@SuppressWarnings("rawtypes")
public List getListByHQL(String datasql, int firstRow, int maxNum, Map<String, Object> values) {
    Query dataQuery = this.createQuery(datasql, values);
    dataQuery.setFirstResult(firstRow);
    dataQuery.setMaxResults(maxNum);
    return dataQuery.list();
}


@SuppressWarnings("unchecked")
public PageFinder<Object> pagedObjectByHQL(String countHql, String hql, int toPage, int pageSize, Map<String, Object> values) {
    Query query = this.createQuery(countHql, values);
    Long totalCount = (Long) query.uniqueResult();
    if (totalCount.intValue() < 1) {
        return new PageFinder<Object>(toPage, pageSize, totalCount.intValue());
    } else {
        PageFinder<Object> finder = new PageFinder<Object>(toPage, pageSize, totalCount.intValue());
        List<Object> list = this.getListByHQL(hql, finder.getStartOfPage(), finder.getPageSize(), values);
        finder.setData(list);
        return finder;
    }
}


@SuppressWarnings("unchecked")
public T getObjectByHql(String hql, Object... values) {
    Query query = this.createQuery(hql, values);
    List<T> list = query.list();
    if (null != list && list.size() > 0) {
        T first = list.get(0);
        for (int i = 1; i < list.size(); i++) {
            if (list.get(i) != first) {
                throw new NonUniqueResultException(list.size());
            }
        }
        return first;
    }
    return null;
}


@SuppressWarnings("unchecked")
public List<T> getListByHql(String hql, Object... values) {
    Query dataQuery = this.createQuery(hql, values);
    return dataQuery.list();
}

@SuppressWarnings("unchecked")
public List<T> getListByHql(String hql, int firstRow, int maxNum, Object... values) {
    Query query = this.createQuery(hql, values);
    query.setFirstResult(firstRow);
    query.setMaxResults(maxNum);
    return query.list();
}


public PageFinder<T> pagedByHQL(String hql, int toPage, int pageSize, Object... values) {
    String countQueryString = " select count(*) " + this.removeSelect(this.removeOrders(hql));
    List<T> countlist = this.getListByHql(countQueryString, values);
    Long totalCount = (Long) countlist.get(0);

    if (totalCount.intValue() < 1) {
        return new PageFinder<T>(toPage, pageSize, totalCount.intValue());
    } else {
        final PageFinder<T> finder = new PageFinder<T>(toPage, pageSize, totalCount.intValue());
        List<T> list = this.getListByHql(hql, finder.getStartOfPage(), finder.getPageSize(), values);
        finder.setData(list);
        return finder;
    }
}


public SQLQuery createSQLQuery(String sql, Object... values) {
    Assert.hasText(sql, "sql 不能为空");
    SQLQuery query = this.getSession().createSQLQuery(sql);
    if (values != null) {
        for (int i = 0; i < values.length; i++) {
            query.setParameter(i, values[i]);
        }
    }
    return query;
}


public SQLQuery createSQLQuery(String sql, Map<String, ?> values) {
    Assert.hasText(sql, "sql 不能为空");
    Query query = this.createSQLQuery(sql);
    if (values != null) {
        query = this.setParameter(query, values);
    }
    return (SQLQuery) query;
}

@SuppressWarnings("unchecked")
public List<Object> getListBySQL(String datasql, Map<String, Object> values) {
    SQLQuery dataQuery = this.createSQLQuery(datasql, values);
    return dataQuery.list();
}

@SuppressWarnings("unchecked")
public List<Object> getListBySQL(String datasql, int firstRow, int maxNum, Map<String, Object> values) {
    SQLQuery dataQuery = this.createSQLQuery(datasql, values);
    dataQuery.setFirstResult(firstRow);
    dataQuery.setMaxResults(maxNum);
    return dataQuery.list();
}


public PageFinder<Object> pagedObjectBySQL(String countsql, String datasql, int toPage, int pageSize, Map<String, Object> values) {
    SQLQuery query = this.createSQLQuery(countsql, values);
    Long totalCount = Long.parseLong(query.uniqueResult().toString());
    if (totalCount.intValue() < 1) {
        return new PageFinder<Object>(toPage, pageSize, totalCount.intValue());
    } else {
        PageFinder<Object> finder = new PageFinder<Object>(toPage, pageSize, totalCount.intValue());
        List<Object> list = this.getListBySQL(datasql, finder.getStartOfPage(), finder.getPageSize(), values);
        finder.setData(list);
        return finder;
    }
}

/**
 * 取得对象的主键值,辅助函数.
 */
@SuppressWarnings("unused")
private Serializable getId(Object entity) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Assert.notNull(entity);
    return (Serializable) PropertyUtils.getProperty(entity, this.getIdName());
}

/**
 * 取得对象的主键名,辅助函数.
 */
private String getIdName() {
    ClassMetadata meta = this.sessionFactory.getClassMetadata(this.entityClass);
    Assert.notNull(meta, "Class " + this.entityClass + " not define in hibernate session factory.");
    String idName = meta.getIdentifierPropertyName();
    Assert.hasText(idName, this.entityClass.getSimpleName() + " has no identifier property define.");
    return idName;
}

/**
 * hql 设置参数
 * 
 * @Title: setParameter
 * @Description: TODO
 * @param query
 * @param map
 * @return
 * @throws
 * @author: yong
 * @date: 2012-12-17下午05:56:15
 */
private Query setParameter(Query query, Map<String, ?> map) {
    if (map != null && !map.isEmpty()) {
        Set<String> keySet = map.keySet();
        for (String string : keySet) {
            Object obj = map.get(string);
            // 这里考虑传入的参数是什么类型,不同类型使用的方法不同
            if (obj instanceof Collection<?>) {
                query.setParameterList(string, (Collection<?>) obj);
            } else if (obj instanceof Object[]) {
                query.setParameterList(string, (Object[]) obj);
            } else {
                query.setParameter(string, obj);
            }
        }
    }
    return query;
}

/**
 * 去除hql的select 子句,未考虑union的情况用于pagedQuery.
 * 
 * @param hql
 * @return
 */
private String removeSelect(String hql) {
    Assert.hasText(hql);
    int beginPos = hql.toLowerCase().indexOf("from");
    Assert.isTrue(beginPos != -1, " hql : " + hql + " must has a keyword 'from'");
    return hql.substring(beginPos);
}

/**
 * 去除hql的orderby 子句,用于pagedQuery.
 * 
 * @param hql
 * @return
 */
private String removeOrders(String hql) {
    Assert.hasText(hql);
    Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(hql);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        m.appendReplacement(sb, "");
    }
    m.appendTail(sb);
    return sb.toString();
}

}

复制代码

  分页工具类PageFinder.java

复制代码
package hello.page;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

/**

  • 分页对象. 包含当前页数据及分页信息
  • */
    @SuppressWarnings("serial")
    public class PageFinder implements Serializable {

    public final static int DEFAULT_PAGE_SIZE = 10;

    /**

    • 每页的记录数 */ private int pageSize = DEFAULT_PAGE_SIZE;

    /**

    • 当前页中存放的数据 */ @Expose @SerializedName("rows") private List data;

    /**

    • 总记录数 */ @Expose @SerializedName("total") private int rowCount;

    /**

    • 页数 */

    @Expose
    @SerializedName("page")
    private int pageCount;

    /**

    • 跳转页数 */ private int pageNo;

    /**

    • 是否有上一页 */ private boolean hasPrevious = false;

    /**

    • 是否有下一页 */ private boolean hasNext = false;

    /**

    • 表格页脚数据 */

    @Expose
    @SerializedName("footer")
    private List> footers;

    public PageFinder() {
    }

    public PageFinder(int pageNo, int rowCount) {
    this.pageNo = pageNo;
    this.rowCount = rowCount;
    this.pageCount = getTotalPageCount();
    refresh();
    }

    /**

    • 构造方法 */ public PageFinder(int pageNo, int pageSize, int rowCount) { this.pageNo = pageNo; this.pageSize = pageSize; this.rowCount = rowCount; this.pageCount = getTotalPageCount(); refresh(); }

    public PageFinder(int pageNo, int pageSize, int rowCount, List data) {
    this.pageNo = pageNo;
    this.pageSize = pageSize;
    this.rowCount = rowCount;
    this.pageCount = getTotalPageCount();
    this.data = data;
    refresh();
    }

    /**

    • 取总页数 */ private final int getTotalPageCount() { if (rowCount % pageSize == 0) return rowCount / pageSize; else return rowCount / pageSize + 1; }

    /**

    • 刷新当前分页对象数据 */ private void refresh() { if (pageCount <= 1) { hasPrevious = false; hasNext = false; } else if (pageNo == 1) { hasPrevious = false; hasNext = true; } else if (pageNo == pageCount) { hasPrevious = true; hasNext = false; } else { hasPrevious = true; hasNext = true; } }

    /**

    • 取每页数据数 */ public int getPageSize() { return pageSize; }

    /**

    • 取当前页中的记录. */ public Object getResult() { return data; }

    public List getData() {
    return data;
    }

    public void setData(List data) {
    this.data = data;
    }

    public int getRowCount() {
    return rowCount;
    }

    public void setRowCount(int rowCount) {
    this.rowCount = rowCount;
    }

    public int getPageCount() {
    return pageCount;
    }

    public void setPageCount(int pageCount) {
    this.pageCount = pageCount;
    }

    public int getPageNo() {
    return pageNo;
    }

    public void setPageNo(int pageNo) {
    this.pageNo = pageNo;
    }

    public boolean isHasPrevious() {
    return hasPrevious;
    }

    public void setHasPrevious(boolean hasPrevious) {
    this.hasPrevious = hasPrevious;
    }

    public boolean isHasNext() {
    return hasNext;
    }

    public void setHasNext(boolean hasNext) {
    this.hasNext = hasNext;
    }

    public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
    }

    public List> getFooters() {
    return footers;
    }

    public void setFooters(List> footers) {
    this.footers = footers;
    }

    /**

    • 获取跳转页第一条数据在数据集的位置 */ public int getStartOfPage() { return ((pageNo - 1)<0?0:pageNo) * pageSize; } }

复制代码

  驱动类Application.java

复制代码
package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;

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

/**
 * 注入sessionfatory
 * @return
 */
@Bean
public HibernateJpaSessionFactoryBean sessionFactory() {
    return new HibernateJpaSessionFactoryBean();
}

}

复制代码

  此时sessionfactory注入成功。

qq_35035078
boboaiya ?刷屏好玩?
一年多之前 回复
xiaohua914
xiaohua914 大哥,你要干啥?我只是想使用注解方式配置druid而已
大约 2 年之前 回复

在springboot配置文件下制定配置文件
用下面制定使用druid连接池
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
再次启动尝试

xiaohua914
xiaohua914 新版本已经不支持这样了
大约 2 年之前 回复

问题我自己已经解决了,是druid版本问题 ,如果用的druid-spring-boot-starter版本为1.1.10 ,那么搭配的druid版本要是1.1.9,其他版本我不知道,但用1.1.10的druid就肯定会出现我上面说的问题,;
现在网上搜索springboot +druid 都是要我们写一堆代码,其实大家可以用druid-spring-boot-starter去做,不用写一句代码,只要配置下就可以了,而且还支持多数据库配置,参考https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter
最后附上pom.xml中druid的配置,

 <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.9</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

查看这篇文章:springboot2集成druid连接池,https://www.jianshu.com/p/170c34bf86a3

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
springboot+druid配置无效

使用druid-spring-boot-starter 提供的配置方法,运行之后应用不到druid连接处,而是默认的HikariPool pom.xml ``` <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.druid</groupId> <artifactId>druid</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>druid</name> <description>测试</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.10</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> ``` 运行的类 ``` package com.druid; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication(scanBasePackages="com.alibaba.druid.spring.boot") public class DruidApplication { public static void main(String[] args) { SpringApplication.run(DruidApplication.class, args); } } ```

springboot2.1.8集成druid连接池 无法实现sql监控

![图片说明](https://img-ask.csdn.net/upload/201910/15/1571113606_898290.jpg) sql监控没有数据 连接池配置: initial-size: 10 # 最大连接数 max-active: 50 #最小连接数 min-idle: 10 #获取连接等待超时时间 max-wait: 5000 pool-prepared-statements: true #是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭。 max-pool-prepared-statement-per-connection-size: 20 validation-query: SELECT 1 FROM DUAL validation-query-timeout: 20000 test-on-borrow: false #申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 test-on-return: false #归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 test-while-idle: true #建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 time-between-eviction-runs-millis: 60000 #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 min-evictable-idle-time-millis: 300000 #一个连接在池中最小生存的时间,单位是毫秒 #通过connectionProperties属性来打开mergeSql功能;慢sql记录 connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 # StatViewServlet配置。(因为暴露的监控信息比较敏感,支持密码加密和访问ip限定) stat-view-servlet: # 是否启用WebStatFilter enabled: true # 访问路径 url-pattern: "/druid/*" # 排除不必要的url exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico" # 监控最大session数,默认是1000 session-stat-max-count: 1000 # 是否启用session的统计功能 session-stat-enable: true # 是否启用监控单个Url调用的sql列表 profile-enable: true # 使druid当前session的用户是谁,session_user_key是你保存到session中的sessionName principalSessionName: session_user_key # 使druid只当当前的user是谁,cookie_user_key是你保存在cookie中的cookieName principalCookieName: cookie_user_key #可以增加访问账号密码【去掉注释就可以】 #login-username: admin #login-password: admin filter: # 监控统计 stat: # 数据库类型 db-type: mysql # 慢SQL log-slow-sql: true # 慢SQL执行时间 slow-sql-millis: 1000 merge-sql: true wall: config: multi-statement-allow: true ###试了各种方法sql监控就是没有出来

Spring Boot配置Session监听无效。

我有一个spring boot (v1.5.9.RELEASE)项目,想要对session进行管理/监听,实现了HttpSessionListener和HttpSessionAttributeListener这两个接口,在MySessionListener中使用@WebListener注解,在启动类中使用@SpringBootApplication注解 但是经过测试,访问网页(ftl页面)无法触发sessionCreated()方法,session过期时也无法触发sessionDestroyed()方法;用户登陆时调用request.getSession().setAttribute()或者session().setAttribute()都无法触发attributeAdded()方法。 程序启动时可以输出构造方法中的内容 2018-01-22 18:02:49.761 INFO 35600 --- [ost-startStop-1] c.t.x.c.listener.MySessionListener : MySessionListenerInitialized 请问有人知道这是为什么吗 代码如下: DemoApplication.java ``` @SpringBootApplication @ServletComponentScan public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } ``` MySessionListener.java ``` @WebListener public class MySessionListener implements HttpSessionListener, HttpSessionAttributeListener { private final static Log log = LogFactory.getLog(MySessionListener.class); // 程序启动时可以在控制台中输出这句话 public MySessionListener() { log.info("MySessionListenerInitialized"); } @Override public void sessionCreated(HttpSessionEvent se) { log.info("sessionCreated-----" + se.getSession().getId()); } @Override public void sessionDestroyed(HttpSessionEvent se) { log.info("sessionDestroyed-----" + se.getSession().getId()); } @Override public void attributeAdded(HttpSessionBindingEvent se) { log.info("attributeAdded: "+se.getSession().getId()); } @Override public void attributeRemoved(HttpSessionBindingEvent se) { log.info("attributeRemoved: "+se.getSession().getId()); } @Override public void attributeReplaced(HttpSessionBindingEvent se) { log.info("attributeReplaced: "+se.getSession().getId()); } } ``` 还有就是使用springbean的配置方式同样无效 ``` @Configuration public class MyWebConfiguration extends WebMvcConfigurerAdapter { @Bean public ServletListenerRegistrationBean<EventListener> sessionListener() { ServletListenerRegistrationBean<EventListener> sessionListener = new ServletListenerRegistrationBean<>(); sessionListener.setListener(new MySessionListener()); return sessionListener; } } ```

springboot 连接不到oracle

java.sql.SQLException: ORA-01017: 用户名/口令无效; 登录被拒绝 at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:509) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:456) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:451) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1040) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:552) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:550) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:268) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:501) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:1292) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:1025) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:793) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:57) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:747) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:562) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:119) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) [HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) [HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) [HikariCP-3.2.0.jar:na] at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157) [spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115) [spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78) [spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82) [mybatis-spring-2.0.1.jar:2.0.1] at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68) [mybatis-spring-2.0.1.jar:2.0.1] at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336) [mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85) [mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) [mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) [mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) [mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) [mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) [mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) [mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) [mybatis-3.5.1.jar:3.5.1] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144] at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_144] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) [mybatis-spring-2.0.1.jar:2.0.1] at com.sun.proxy.$Proxy58.selectList(Unknown Source) [na:na] at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230) [mybatis-spring-2.0.1.jar:2.0.1] at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) [mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) [mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58) [mybatis-3.5.1.jar:3.5.1] at com.sun.proxy.$Proxy59.list(Unknown Source) [na:na] at com.bw.service.T_UserServiceImpl.list(T_UserServiceImpl.java:51) [classes/:na] at com.bw.controller.T_UserController.list(T_UserController.java:27) [classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144] at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_144] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189) [spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) [spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) [spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) [spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800) [spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) [spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) [spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) [spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) [spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897) [spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) [spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) [spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) [spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) [spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.16.jar:9.0.16] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_144] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_144] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.16.jar:9.0.16] at java.lang.Thread.run(Unknown Source) [na:1.8.0_144] 2019-08-14 16:43:34.873 ERROR 31464 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: ORA-01017: 用户名/口令无效; 登录被拒绝 ### The error may exist in file [F:\DianShang\YongHu\target\classes\com\bw\mapper\T_UserMapper.xml] ### The error may involve com.bw.mapper.T_UserMapper.list ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: ORA-01017: 用户名/口令无效; 登录被拒绝 ] with root cause java.sql.SQLException: ORA-01017: 用户名/口令无效; 登录被拒绝 at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:509) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:456) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:451) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1040) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:552) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:550) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:268) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:501) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:1292) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:1025) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:793) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:57) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:747) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:562) ~[ojdbc8-19.3.0.0.0.jar:19.3.0.0.0] at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:119) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.2.0.jar:na] at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82) ~[mybatis-spring-2.0.1.jar:2.0.1] at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68) ~[mybatis-spring-2.0.1.jar:2.0.1] at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[mybatis-3.5.1.jar:3.5.1] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144] at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_144] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) ~[mybatis-spring-2.0.1.jar:2.0.1] at com.sun.proxy.$Proxy58.selectList(Unknown Source) ~[na:na] at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230) ~[mybatis-spring-2.0.1.jar:2.0.1] at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) ~[mybatis-3.5.1.jar:3.5.1] at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58) ~[mybatis-3.5.1.jar:3.5.1] at com.sun.proxy.$Proxy59.list(Unknown Source) ~[na:na] at com.bw.service.T_UserServiceImpl.list(T_UserServiceImpl.java:51) ~[classes/:na] at com.bw.controller.T_UserController.list(T_UserController.java:27) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144] at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_144] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.16.jar:9.0.16] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_144] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_144] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.16.jar:9.0.16] at java.lang.Thread.run(Unknown Source) [na:1.8.0_144] plsql能连接用户,但是项目死活就是连不上百度了好多方法都不行

SpringBoot连接Oracle数据库报ORA-01017: invalid username/password; logon denied

我本地用Sql Developer 和 Navicat连接都没问题,但是在项目中连接运行就报错。 我项目中已经导入ojdbc的jar包了,谁知道该怎么连数据库阿!!!!! ![图片说明](https://img-ask.csdn.net/upload/201911/24/1574566960_128010.png) ![图片说明](https://img-ask.csdn.net/upload/201911/24/1574566967_439930.png) 有人告诉我该怎么做吗

springboot启动,一直报异常maxActive can't not set zero,配置文件写的没问题呀?

![图片说明](https://img-ask.csdn.net/upload/201911/18/1574045263_140188.png) springboot启动,一直报异常maxActive can't not set zero,配置文件写的没问题呀?![图片说明](https://img-ask.csdn.net/upload/201911/18/1574058322_504276.png) yml配置是匹配的,但是这些属性都没有,不是null,就是0

springBoot使用注解注入失败

**useMapper的xml文件** ``` <mapper namespace="com.auto.dao.UserMapper"> <select id="findByName" parameterType="String" resultType="User"> select * from t_user where username=#{username} </select> </mapper> ``` **mapper接口代码** ``` public interface UserMapper { public User findByName(String username); } ``` **springboot启动类的代码** ``` @SpringBootApplication @MapperScan("com.auto.dao") public class App { public static void main(String[] args) { SpringApplication.run(App.class,args); } } ``` **pom.xml文件配置** ``` <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> </parent> <groupId>com.auto</groupId> <artifactId>MavenDay01</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <!-- spirngBoot启动器 --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <!-- jstl --> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> ``` **user的实体类** ``` @Repository public class User { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return "User [username=" + username + ", password=" + password + "]"; } } ``` **这是properties的配置文件** ``` spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/mysql spring.datasource.username=root spring.datasource.password=123456 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource mybatis.type-aliases-package=com.auto.entity 实体类和mapper.xml文件都在这包里面 server.port=9090 spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp ``` **我写了个service接口,然后写了个实现类重写findByName方法返回userMapper中方法,在实现类中注入了userMapper接口,这里无法使用@Autowired注入** ``` @Service @Transactional public class UserServiceImpl implements UserService{ @Resource UserMapper userMapper; @Override public User findByName(String username) { return userMapper.findByName(username); } } ``` **报错** ``` org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.auto.dao.UserMapper.findByName ``` 总是报找不到接口,加上注解标记也没用,换成在接口上用@mapper注解也不行,是什么问题,我在网上看说有什么依赖包冲突问题,但我换了几个版本也不行; **问题已经解决:** 问题出在没有在properties文件中添加mapper.xml文件的扫描路径 解决办法:在properties文件中加上 mybatis.mapper-locations=com/.../.../*.xml 这里是mapper.xml文件的路径

springboot整合mybatis-plus无法映射xml文件

异常信息: ```org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)``` 异常原因排除: 1. 项目正常启动 2. mybaits-plus配置mapper.xml扫描没问题 ```xml mybatis-plus: # 配置扫描xml mapper-locations: classpath*:mapper/*/*Mapper.xml # 实体扫描,多个package用逗号或者分号分隔 type-aliases-package: org.cnplo.control.modules.admin.domain ``` 3. mapperscan扫描mapper正常 4.mybatis-plus的配置文件 MybatisPlusConfig配置 ```java @Configuration @MapperScan("org.cnplo.control.modules.*.mapper") public class MybatisPlusConfig { /** * 乐观锁插件 */ @Bean public OptimisticLockerInterceptor optimisticLockerInterceptor() { return new OptimisticLockerInterceptor(); } /** * mybatis-plus分页插件 */ @Bean public PaginationInterceptor paginationInterceptor() { return new PaginationInterceptor(); } } ``` DruidDataSourceConfig配置 ```java @Configuration public class DruidDataSourceConfig { /** * @return DruidDataSource */ @Bean @ConfigurationProperties(prefix = "spring.datasource") public DruidDataSource druidDataSource() { return new DruidDataSource(); } /** * 配置事物管理器 */ @Bean public DataSourceTransactionManager transactionManager() { return new DataSourceTransactionManager(druidDataSource()); } } ``` 项目正常启动,执行数据库请求的时候异常BindingException。请问这是什么问题,大胆猜测是哪个jar包升级引起的,还请大佬们不吝赐教 ``` <properties> <java.version>1.8</java.version> <json.version>1.2.54</json.version> <druid.version>1.1.20</druid.version> <swagger.version>2.7.0</swagger.version> <mybatisplus.version>3.3.1.tmp</mybatisplus.version> </properties> <dependencies> <!--web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!--druid--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- mybatisplus与springboot整合 --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>${mybatisplus.version}</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>${mybatisplus.version}</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-autoconfigure</artifactId> <version>1.3.2</version> </dependency> <!-- swagger2 rest api start--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${swagger.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger.version}</version> </dependency> <!--json工具--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${json.version}</version> </dependency> <!-- jwt --> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>0.9.1</version> </dependency> <!--redis--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!--thymeleaf--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!--test--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> ```

spring AOP 拦截器方式配置事务失效

Spring.xml配置如下 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <!-- 引入属性文件 --> <context:property-placeholder location="classpath:config.properties" /> <!-- 自动扫描dao和service包(自动注入) --> <context:component-scan base-package="com.zfy.db.dao,com.zfy.service" /> </beans> spring-mybatis.xml配置文件如下 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd "> <!-- JNDI方式配置数据源 --><!-- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="${jndiName}"></property> </bean> --><!-- 配置数据源 --> <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="url" value="${jdbc_url}" /> <property name="username" value="${jdbc_username}" /> <property name="password" value="${jdbc_password}" /> <property name="initialSize" value="0" /> <property name="maxActive" value="20" /> <property name="maxIdle" value="20" /> <property name="minIdle" value="0" /> <property name="maxWait" value="60000" /> <property name="validationQuery" value="${validationQuery}" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <property name="testWhileIdle" value="true" /> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <property name="minEvictableIdleTimeMillis" value="25200000" /> <property name="removeAbandoned" value="true" /> <property name="removeAbandonedTimeout" value="1800" /> <property name="logAbandoned" value="true" /> <property name="filters" value="mergeStat" /> </bean> <!-- myBatis文件 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 --> <property name="mapperLocations"> <array> <value>classpath:com/zfy/mapper/portal/*.xml</value> <value>classpath:com/zfy/mapper/permission/*.xml</value> <value>classpath:com/zfy/mapper/form/*.xml</value> </array> </property> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.zfy.db.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean> <!-- 拦截器方式配置事物 --> <tx:advice id="transactionAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="append*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Exception"/> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="modify*" propagation="REQUIRED" /> <tx:method name="edit*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="repair" propagation="REQUIRED" /> <tx:method name="delAndRepair" propagation="REQUIRED" /> <tx:method name="get*" propagation="SUPPORTS" /> <tx:method name="find*" propagation="SUPPORTS" /> <tx:method name="load*" propagation="SUPPORTS" /> <tx:method name="all*" propagation="SUPPORTS" /> <tx:method name="search*" propagation="SUPPORTS" /> <tx:method name="datagrid*" propagation="SUPPORTS" /> <tx:method name="*" propagation="SUPPORTS" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="transactionPointcut" expression="execution(* com.zfy.service..*.*impl.*(..))" /> <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" /> </aop:config> <!-- 配置druid监控spring jdbc --> <bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor"> </bean> <bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype"> <property name="patterns"> <list> <value>com.zfy.service.*</value> </list> </property> </bean> <aop:config> <aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut" /> </aop:config> </beans> 项目架构 DAO接口: com.zfy.db.dao.form.FormSubjectMapper package com.zfy.db.dao.form; import com.zfy.db.model.form.FormSubject; public interface FormSubjectMapper { int insert(FormSubject record); } Service : com.zfy.service.form.FormSubjectService package com.zfy.service.form; import com.zfy.db.model.form.FormSubject; /** * @author keke * @version 创建时间:2013-5-15 下午11:05:45 * */ public interface FormSubjectService { public int insert(FormSubject record) throws Exception; } ServiceImpl: com.zfy.service.form.impl.FormSubjectServiceImpl package com.zfy.service.form.impl; import com.zfy.db.model.form.FormSubject; public int insert(FormSubject record){ FormSubject fs = new FormSubject(); fs.setFormCode(3); fs.setFormName("张三123"); for (int i = 0; i <2; i++) { mapper.insert(fs); } return 0; } } mybatis 配置文件 FormSubjectMapper.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.zfy.db.dao.form.FormSubjectMapper" > <resultMap id="BaseResultMap" type="com.zfy.db.model.form.FormSubject" > <id column="FORM_CODE" property="formCode" jdbcType="INTEGER" /> <result column="FORM_NAME" property="formNam" jdbcType="VARCHAR" /> </resultMap> <insert id="insert" parameterType="com.zfy.db.model.form.FormSubject" > insert into FORM_SUBJECT (FORM_CODE, FORM_NAME) values (#{formCode,jdbcType=INTEGER}, #{formName,jdbcType=VARCHAR}) </insert> </mapper> Junit 测试类: @Test public void test1() throws Exception{ try { formSubjectService.insert( null); }} catch (RuntimeException e) { e.printStackTrace(); } } 开发路线: Spring3.1 mybatis 3.1 运行之后。“张三”是插入进去了,但“李四 ”存在 违反唯一约束条件,没有回滚,所以事务没有起到作用。请大家帮忙看看。谢谢啦! 在线等……

springboot+mybatis(xml模式) 项目 单元测试 报错。

2017-09-01 17:35:21.034 INFO 11212 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.lxhw.module.jbxx.dao.DjKjfCzryDao.getCzry at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:230) at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48) at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58) at com.sun.proxy.$Proxy98.getCzry(Unknown Source) at com.lxhw.module.jbxx.service.DjKjfCzryService.getCzry(DjKjfCzryService.java:47) at com.lxhw.module.jbxx.service.DjKjfCzryService$$FastClassBySpringCGLIB$$30938009.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) at com.lxhw.module.jbxx.service.DjKjfCzryService$$EnhancerBySpringCGLIB$$428d2624.getCzry(<generated>) at com.lxhw.module.jbxx.service.DjKjfCzryServiceTest.searchCzry(DjKjfCzryServiceTest.java:21) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 这个是报错信息 项目运行正常,就是不能单元测试 初步估计是DjKjfCzryDao.class和DjKjfCzryDao.xml没有匹配上。但是run application是正常的,只有junit的时候有问题 是不是和引入mybais-spring-boot-starter有关系,不能自动去取配置文件了。

spring + mybatis 事物不起作用,无法回滚

spring + mybatis 事物不起作用,无法回滚:求解 设置如下: <!-- proxy-target-class默认"false",更改为"ture"使用CGLib动态代理 --> <aop:aspectj-autoproxy proxy-target-class="true" /> <!-- 基于Druid数据库链接池的数据源配置 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="initialSize" value="${pool.initialSize}" /> <property name="minIdle" value="${pool.minIdle}" /> <property name="maxActive" value="${pool.maxActive}" /> <property name="maxWait" value="${pool.maxWait}" /> <property name="timeBetweenEvictionRunsMillis" value="${pool.timeBetweenEvictionRunsMillis}" /> <property name="minEvictableIdleTimeMillis" value="${pool.minEvictableIdleTimeMillis}" /> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow" value="true" /> <property name="testOnReturn" value="false" /> <property name="validationQuery" value="${jdbc.validationQuery}" /> <property name="filters" value="config" /> <property name="connectionProperties" value="config.decrypt=true;config.decrypt.key=${jdbc.publickey}" /> </bean> <!-- 将数据源映射到sqlSessionFactory中 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mapperLocations" value="classpath*:mapper/*.Mapper.xml" /> <property name="configLocation" value="classpath:config/mybatis-config.xml" /> </bean> <!-- SqlSession模板类实例 --> <bean id="sessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="close"> <constructor-arg index="0" ref="sqlSessionFactory" /> </bean> <!--======= 事务配置 Begin ================= --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- <aop:pointcut id="txPointcut" expression="execution(* com.enjoy.system.service..*(..)) or execution(* com.enjoy.commodity.service..*(..))" /> --> <aop:config> <aop:pointcut id="txPointcut" expression="(execution(* com.enjoy.system.service..*(..)) or execution(* com.enjoy.commodity.service..*(..)))" /> <aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="set*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="edit*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="init*" propagation="REQUIRED" /> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="count*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="list*" propagation="REQUIRED" read-only="true" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> 求解!!

关于sping的datasource的url的配置

我想要在spring中使用jdbcTemplate,需要配置数据源,而我使用的是access数据库,放在webroot目录下的data文件夹中的1.mdb,我的问题是我怎样配置datasource的url, <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver"/> <property name="url" value="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};[color=red]DBQ=http://127.0.0.1:8088/jpck1.2/Data/1.mdb[/color]"/> <property name="username" value=""/> <property name="password" value=""/> </bean> 上面那样子写会报org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory ([Microsoft][ODBC Microsoft Access Driver] 文件名无效。) 同样的 用DBQ=Data/1.mdb也会报错.但是用绝对路径E://..... 就不会报错了. 但是我需要用 相对路径, 在applicationContext中能不能有一种方法像web.xml中读取applicationContext.xml一样,使用[color=red]classpath [/color]关键字,直接找到web-inf的class目录..

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

Vue + Spring Boot 项目实战(十九):Web 项目优化解决方案

快来一起探索如何打脸我们的破项目,兄弟姐妹们把害怕打在公屏上!

你连存活到JDK8中著名的Bug都不知道,我怎么敢给你加薪

CopyOnWriteArrayList.java和ArrayList.java,这2个类的构造函数,注释中有一句话 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public ArrayList(Collection&lt;? ...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

CSDN:因博主近期注重写专栏文章(已超过150篇),订阅博主专栏人数在突增,近期很有可能提高专栏价格(已订阅的不受影响),提前声明,敬请理解!

CSDN:因博主近期注重写专栏文章(已超过150篇),订阅博主专栏人数在突增,近期很有可能提高专栏价格(已订阅的不受影响),提前声明,敬请理解! 目录 博客声明 大数据了解博主粉丝 博主的粉丝群体画像 粉丝群体性别比例、年龄分布 粉丝群体学历分布、职业分布、行业分布 国内、国外粉丝群体地域分布 博主的近期访问每日增量、粉丝每日增量 博客声明 因近期博主写专栏的文章越来越多,也越来越精细,逐步优化文章。因此,最近一段时间,订阅博主专栏的人数增长也非常快,并且专栏价

一个HashMap跟面试官扯了半个小时

一个HashMap能跟面试官扯上半个小时 关注 安琪拉的博客 1.回复面试领取面试资料 2.回复书籍领取技术电子书 3.回复交流领取技术电子书 前言 HashMap应该算是Java后端工程师面试的必问题,因为其中的知识点太多,很适合用来考察面试者的Java基础。 开场 面试官: 你先自我介绍一下吧! 安琪拉: 我是安琪拉,草丛三婊之一,最强中单(钟馗不服)!哦,不对,串场了,我是**,目...

我说我不会算法,阿里把我挂了。

不说了,字节跳动也反手把我挂了。

记录下入职中软一个月(外包华为)

我在年前从上一家公司离职,没想到过年期间疫情爆发,我也被困在家里,在家呆着的日子让人很焦躁,于是我疯狂的投简历,看面试题,希望可以进大公司去看看。 我也有幸面试了我觉得还挺大的公司的(虽然不是bat之类的大厂,但是作为一名二本计算机专业刚毕业的大学生bat那些大厂我连投简历的勇气都没有),最后选择了中软,我知道这是一家外包公司,待遇各方面甚至不如我的上一家公司,但是对我而言这可是外包华为,能...

面试:第十六章:Java中级开发

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

培训班出来的人后来都怎么样了?(二)

接着上回说,培训班学习生涯结束了。后面每天就是无休止的背面试题,不是没有头脑的背,培训公司还是有方法的,现在回想当时背的面试题好像都用上了,也被问到了。回头找找面试题,当时都是打印下来天天看,天天背。 不理解呢也要背,面试造飞机,上班拧螺丝。班里的同学开始四处投简历面试了,很快就有面试成功的,刚开始一个,然后越来越多。不知道是什么原因,尝到胜利果实的童鞋,不满足于自己通过的公司,嫌薪水要少了,选择...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

工作八年,月薪60K,裸辞两个月,投简历投到怀疑人生!

近日,有网友在某职场社交平台吐槽,自己裸辞两个月了,但是找工作却让自己的心态都要崩溃了,全部无果,不是已查看无回音,就是已查看不符合。 “工作八年,两年一跳,裸辞两个月了,之前月薪60K,最近找工作找的心态崩了!所有招聘工具都用了,全部无果,不是已查看无回音,就是已查看不符合。进头条,滴滴之类的大厂很难吗???!!!投简历投的开始怀疑人生了!希望 可以收到大厂offer” 先来看看网...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

都前后端分离了,咱就别做页面跳转了!统统 JSON 交互

文章目录1. 无状态登录1.1 什么是有状态1.2 什么是无状态1.3 如何实现无状态1.4 各自优缺点2. 登录交互2.1 前后端分离的数据交互2.2 登录成功2.3 登录失败3. 未认证处理方案4. 注销登录 这是本系列的第四篇,有小伙伴找不到之前文章,松哥给大家列一个索引出来: 挖一个大坑,Spring Security 开搞! 松哥手把手带你入门 Spring Security,别再问密...

97年世界黑客编程大赛冠军作品(大小仅为16KB),惊艳世界的编程巨作

这是世界编程大赛第一名作品(97年Mekka ’97 4K Intro比赛)汇编语言所写。 整个文件只有4095个字节, 大小仅仅为16KB! 不仅实现了3D动画的效果!还有一段震撼人心的背景音乐!!! 内容无法以言语形容,实在太强大! 下面是代码,具体操作看最后! @echo off more +1 %~s0|debug e100 33 f6 bf 0 20 b5 10 f3 a5...

程序员是做全栈工程师好?还是专注一个领域好?

昨天,有位大一的同学私信我,说他要做全栈工程师。 我一听,这不害了孩子么,必须制止啊。 谁知,讲到最后,更确定了他做全栈程序员的梦想。 但凡做全栈工程师的,要么很惨,要么很牛! 但凡很牛的,绝不是一开始就是做全栈的! 全栈工程师听起来好听,但绝没有你想象的那么简单。 今天听我来给你唠,记得帮我点赞哦。 一、全栈工程师的职责 如果你学习编程的目的只是玩玩,那随意,想怎么学怎么学。...

不要再到处使用 === 了

我们知道现在的开发人员都使用 === 来代替 ==,为什么呢?我在网上看到的大多数教程都认为,要预测 JavaScript 强制转换是如何工作这太复杂了,因此建议总是使用===。这些都...

什么是a站、b站、c站、d站、e站、f站、g站、h站、i站、j站、k站、l站、m站、n站?00后的世界我不懂!

A站 AcFun弹幕视频网,简称“A站”,成立于2007年6月,取意于Anime Comic Fun,是中国大陆第一家弹幕视频网站。A站以视频为载体,逐步发展出基于原生内容二次创作的完整生态,拥有高质量互动弹幕,是中国弹幕文化的发源地;拥有大量超粘性的用户群体,产生输出了金坷垃、鬼畜全明星、我的滑板鞋、小苹果等大量网络流行文化,也是中国二次元文化的发源地。 B站 全称“哔哩哔哩(bilibili...

十个摸鱼,哦,不对,是炫酷(可以玩一整天)的网站!!!

文章目录前言正文**1、Kaspersky Cyberthreat real-time map****2、Finding Home****3、Silk – Interactive Generative Art****4、Liquid Particles 3D****5、WINDOWS93****6、Staggering Beauty****7、Ostagram图片生成器网址****8、全历史网址*...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

用了这个 IDE 插件,5分钟解决前后端联调!

点击上方蓝色“程序猿DD”,选择“设为星标”回复“资源”获取独家整理的学习资料!作者 |李海庆我是一个 Web 开发前端工程师,受到疫情影响,今天是我在家办公的第78天。开发了两周,...

大厂的 404 页面都长啥样?最后一个笑了...

每天浏览各大网站,难免会碰到404页面啊。你注意过404页面么?猿妹搜罗来了下面这些知名网站的404页面,以供大家欣赏,看看哪个网站更有创意: 正在上传…重新上传取消 腾讯 正在上传…重新上传取消 网易 淘宝 百度 新浪微博 正在上传…重新上传取消 新浪 京东 优酷 腾讯视频 搜...

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

代码注释如此沙雕,会玩还是你们程序员!

某站后端代码被“开源”,同时刷遍全网的,还有代码里的那些神注释。 我们这才知道,原来程序员个个都是段子手;这么多年来,我们也走过了他们的无数套路… 首先,产品经理,是永远永远吐槽不完的!网友的评论也非常扎心,说看这些代码就像在阅读程序员的日记,每一页都写满了对产品经理的恨。 然后,也要发出直击灵魂的质问:你是尊贵的付费大会员吗? 这不禁让人想起之前某音乐app的穷逼Vip,果然,穷逼在哪里都是...

Java14 新特性解读

Java14 已于 2020 年 3 月 17 号发布,官方特性解读在这里:https://openjdk.java.net/projects/jdk/14/以下是个人对于特性的中文式...

前端还能这么玩?(女朋友生日,用前端写了一个好玩的送给了她,高兴坏了)

前端还能这么玩?(女朋友生日,用前端写了一个好玩的送给了她,高兴坏了)

爬虫(101)爬点重口味的

小弟最近在学校无聊的很哪,浏览网页突然看到一张图片,都快流鼻血。。。然后小弟冥思苦想,得干一点有趣的事情python 爬虫库安装https://s.taobao.com/api?_ks...

工作两年简历写成这样,谁要你呀!

作者:小傅哥 博客:https://bugstack.cn 沉淀、分享、成长,让自己和他人都能有所收获! 一、前言 最近有伙伴问小傅哥,我的简历怎么投递了都没有反应,心里慌的很呀。 工作两年了目前的公司没有什么大项目,整天的维护别人的代码,有坑也不让重构,都烦死了。荒废我一身技能无处施展,投递的简历也没人看。我是不动物园里的猩猩,狒狒了! 我要加班,我要996,我要疯狂编码,求给我个机会… ...

正点原子:STM32F103(战舰)、STM32F407(探索者)、STM32F103(MINI)原理图和PCB

正点原子:STM32F103(战舰)、STM32F407(探索者)、STM32F103(MINI)原理图和PCB

讲真,这两款idea插件,能治愈你英语不好的病

时不时就有小伙伴问我,“二哥,能推荐一款 IDE 吗?”你看这话问的,现在搞 Java 的不都在用 Intellij IDEA 吗,还用得着推荐(我已经和 Eclipse 分手了)。然后小伙伴又说,“二哥,IDEA 支持中文吗?我英语不太好。”你看这话问的,搞编程的,英语不好是硬伤啊! 不过,随着 IDEA 最新版(版本号是 2020.1)的发布,英语不好的病可以彻底治愈了。为什么这么说呢?因为 ...

面试官给我挖坑:a[i][j] 和 a[j][i] 有什么区别?

点击上方“朱小厮的博客”,选择“设为星标”后台回复&#34;1024&#34;领取公众号专属资料本文以一个简单的程序开头——数组赋值:int LEN = 10000; int[][] ...

大专学历就职会不会有瓶颈?

二哥,看了你的那篇外包程序员的文章,想问问您,大专学历以后就职会不会有瓶颈,升职难什么的? 以上是读者阿莫私信我的一个问题,我觉得很有必要认真地谈一谈。单从这个问句上,我现在就可以给出一个无比肯定的回答:“谁要说没有瓶颈,那绝对是骗人的。” 先说一点。这句提问很简短,但有一个瑕疵,眼睛雪亮的读者一眼就能看得出来——先用了“你”,再用了“您”。不是我在故意鸡蛋里挑骨头,我没那么闲,用“您”肯定...

又一起程序员被抓事件

就在昨天互联网又发生一起让人心酸的程序员犯罪事件,著名的百度不限速下载软件 Pandownload PC 版作者被警方抓获。案件大致是这样的:软件的作者不仅非法盗取用户数据,还在QQ群进...

被阿里舍弃,2020年了,还有人在迷恋Oracle数据库?

数据库领域,有曾经被誉为地球最强的——Oracle数据库。 注意,这里说的是Oracle数据库,并非Oracle公司。在Oracle数据库最为顶峰的时候,世界500强、互联网公司、业界的DBA码农们,都将Oracle数据库其视为圣神不可侵犯的领袖。毫不夸张的说,那时的Oracle数据库,天上天下,唯我独尊。 那时虽然有IBM DB2、Microsoft SQL Server、Syba...

14个提高代码质量的好问题

阅读本文大概需要 2.6 分钟。并不是代码写的越多,代码的质量就越高。思考才是。解决一个问题,打开电脑就手撕代码,最终的结果往往是各种代码问题,经过一系列迭代后,代码积重难返,最终的结果...

Mysql性能优化:为什么count(*)这么慢?

导读在开发中一定会用到统计一张表的行数,比如一个交易系统,老板会让你每天生成一个报表,这些统计信息少不了sql中的count函数。但是随着记录越来越多,查询的速度会越来越慢,为什么会这样...

相关热词 c# 局部 截图 页面 c#实现简单的文件管理器 c# where c# 取文件夹路径 c# 对比 当天 c# fir 滤波器 c# 和站 队列 c# txt 去空格 c#移除其他类事件 c# 自动截屏
立即提问