<parent>
<groupId>com.tct.bigdata</groupId>
<artifactId>teye-analyze</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>report</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>report</name>
<description>Report picture and chart to web page</description>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.tct.bigdata</groupId>
<artifactId>data-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!--Redis 数据库读写依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--spring2.0集成redis所需common-pool2-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.2</version>
</dependency>
<!--fastJson支持-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.56</version>
</dependency>
</dependencies>
<build>
<finalName>bigdata-report</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<!-- 释放打包时过滤 -->
<!--<configuration>
<layout>ZIP</layout>
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>-->
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.tct.bigdata.report.ReportApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
原因:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“Hibernate Configuration”的bean时出错:通过字段“ReadDataSource01”表示的不满足依赖项;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建类路径资源[COM/TCT/BigData/Report/Config/DataSourceConfiguration.class]中定义的名为“ReadDataSource01”的bean时出错:bean初始化失败;嵌套异常为org.springframework.beans.factory.beanCreationException:创建名为“org.springframework.boot.autocigure.jdbc.DataSourceInitializerInvoker”的bean时出错:调用init方法失败;嵌套异常为org.springframework.beans.factory.beanCurrentlyIncreationException:创建名为“data source”的bean时出错:请求的bean当前正在创建中:是否存在不可解析的循环引用?
下面是我的配置类:
@Configuration
public class DataSourceConfiguration {
private static Logger log = LoggerFactory.getLogger(DataSourceConfiguration.class);
@Value("${mysql.datasource.type}")
private Class<? extends DataSource> dataSourceType;
/**
* 写库 数据源配置
* @return
*/
@Bean(name = "writeDataSource")
@ConfigurationProperties(prefix = "mysql.datasource.write")
public DataSource writeDataSource() {
log.info("-------------------- writeDataSource init ---------------------");
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder = dataSourceBuilder.type(dataSourceType);
DataSource dataSource = dataSourceBuilder.build();
return dataSource;
}
/**
* 有多少个从库就要配置多少个
* @return
*/
@Bean(name = "readDataSource01")
@ConfigurationProperties(prefix = "mysql.datasource.read01")
public DataSource readDataSourceOne() {
log.info("-------------------- read01 DataSourceOne init ---------------------");
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder = dataSourceBuilder.type(dataSourceType);
return dataSourceBuilder.build();
// return DataSourceBuilder.create().type(dataSourceType).build();
}
}
@Configuration
@AutoConfigureAfter(DataSourceConfiguration.class)
public class HibernateConfiguration {
private static Logger log = LoggerFactory.getLogger(HibernateConfiguration.class);
@Value("${mysql.datasource.readSize}")
private String readDataSourceSize;
@Autowired
@Qualifier("writeDataSource")
private DataSource writeDataSource;
@Autowired
@Qualifier("readDataSource01")
private DataSource readDataSource01;
/**
* 把所有数据库都放在路由中
* @return
*/
@Primary
@Bean(name="dataSource")
public AbstractRoutingDataSource roundRobinDataSouceProxy() {
Map<Object, Object> targetDataSources = new HashMap<Object, Object>();
//把所有数据库都放在targetDataSources中,注意key值要和determineCurrentLookupKey()中代码写的一至,
//否则切换数据源时找不到正确的数据源
targetDataSources.put(DataSourceType.write.getType(), writeDataSource);
targetDataSources.put(DataSourceType.read.getType()+"1", readDataSource01);
final int readSize = Integer.parseInt(readDataSourceSize);
//路由类,寻找对应的数据源
AbstractRoutingDataSource proxy = new AbstractRoutingDataSource(){
private AtomicInteger count = new AtomicInteger(0);
/**
* 这是AbstractRoutingDataSource类中的一个抽象方法,
* 而它的返回值是你所要用的数据源dataSource的key值,有了这个key值,
* targetDataSources就从中取出对应的DataSource,如果找不到,就用配置默认的数据源。
*/
@Override
protected Object determineCurrentLookupKey() {
String typeKey = DataSourceContextHolder.getReadOrWrite();
if(typeKey == null){
return DataSourceType.write.getType();
}
if (typeKey.equals(DataSourceType.write.getType())){
return DataSourceType.write.getType();
}
//读库, 简单负载均衡
int number = count.getAndAdd(1);
int lookupKey = number % readSize;
log.info("使用数据库read-"+(lookupKey+1));
return DataSourceType.read.getType()+(lookupKey+1);
}
};
proxy.setDefaultTargetDataSource(writeDataSource);//默认库
proxy.setTargetDataSources(targetDataSources);
return proxy;
}
}
请显示您的配置类。
顺便说一下,您在Maven中有一些重复:data-redis是重复的。我也怀疑您是否同时需要data-jpa和data-jdbc,但这取决于您
根据您所描述的,由于依赖项重复,问题可能出在您的“true”类路径(由jar中的maven构建,而不是由IDEA构建)上
当打开同时使用这两个bean的页面时,我会看到异常: 请告知如何修复此异常。 编辑:我尝试使用setter注入,正如答案中所引用的那样
该作业工作正常,但每次运行该应用程序时,它都会给出一些警告消息: 我减少了以下警告消息: 我注意到job class中的自动服务正在导致它,但为什么呢?我该怎么做才能摆脱这些警告信息? MyService.java 石英.属性
我已经在我的Spring Boot应用程序中实现了一个调度程序例程,使用Quartz Scheduler遵循本教程(sping-boo-quitz-demo),并为我的目的做了一些修改。 例如,我的作业服务必须能够列出数据库中的所有对象及其子对象,设置新值并最终更新。所有这些都必须是事务性的。 出于某种原因,MyWork类不允许在其中声明事务性方法,所以我通过注入一个带有事务性方法的新服务类来解决
一切都开始了,因为Spring Cloud AWS没有正确配置SimpleStorage原型解决方案。此类负责在使用ResourceLoader时处理s3://协议。有关更多详细信息,请参阅问题:无法在Spring AWS示例上强制转换为org.springframework.core.io.WritableResource。 所以,我不得不手动创建它。但我也在使用LocalStack解决方案(h
我有一个批处理配置。我看到批处理过程默认使用。相反,我需要使用MySQL按批处理发送所有执行细节。但是当我使用以下代码时,我收到以下错误, 创建名称为“batchDataSource”的 Bean 时出错:请求的 Bean 当前正在创建中:是否存在无法解析的循环引用? 在我正在使用属性文件中, 我错过了什么?我正在使用JPA。甚至为什么它不使用可用的JPA数据源?如何在MemoryMap中强制Sp
我正在从事SpringBoot与Spring集成项目。升级应用程序时,我遇到以下错误(仅在pivotal cloud上,而不是本地)- 上下文初始化期间遇到异常-取消刷新尝试:org。springframework。豆。工厂未满足的依赖项异常:创建名为“cloudDataBaseConfiguration”的bean时出错:通过字段“cloud”表示未满足的依赖项:创建名为“cloudMultiH