Ao executar o código da aula eu recebo o erro
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> Split[simple{${body}} -> [process[Processor@0xc6634d], SetBody[simple{Simple: insert into negociacao(preco, quantidade, data) values (${property.preco}, ${property.quantidade}, '${property.data}')}], Log[${body}], Delay[{1000} -> [To[jdbc:mysql]]]]] <<< in route: Route(route1)[[From[timer://negociacoes?fixedRate=true&delay... because of Failed to resolve endpoint: jdbc://mysql due to: No bean could be found in the registry for: mysql of type: javax.sql.DataSource
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1072)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196)
br.com.caelum.camel.RotaHttpPollingNegociacoes.main(RotaHttpPollingNegociacoes.java:68)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jdbc://mysql due to: No bean could be found in the registry for: mysql of type: javax.sql.DataSource
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:587)
at
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: mysql of type: javax.sql.DataSource
at org.apache.camel.util.CamelContextHelper.mandatoryLookup(CamelContextHelper.java:159)
O meu código está assim:
package br.com.caelum.camel;
import java.text.SimpleDateFormat;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.dataformat.xstream.XStreamDataFormat;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.SimpleRegistry;
import com.mysql.cj.jdbc.MysqlConnectionPoolDataSource;
import com.thoughtworks.xstream.XStream;
public class RotaHttpPollingNegociacoes {
public static void main(String[] args) throws Exception {
SimpleRegistry registro = new SimpleRegistry();
registro.put("mysql", criaDataSource());
CamelContext context = new DefaultCamelContext();
final XStream xStream = new XStream();
xStream.alias("negociacao", Negociacao.class);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer://negociacoes?fixedRate=true&delay=3s&period=360s").
to("http4://argentumws.caelum.com.br/negociacoes").
convertBodyTo(String.class).
unmarshal(new XStreamDataFormat(xStream)).
split(body()).
process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Negociacao negociacao = exchange.getIn().getBody(Negociacao.class);
exchange.setProperty("preco", negociacao.getPreco());
exchange.setProperty("quantidade", negociacao.getQuantidade());
String data = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss").format(negociacao.getData().getTime());
exchange.setProperty("data", data);
}
}).
setBody(simple("insert into negociacao(preco, quantidade, data) values (${property.preco}, ${property.quantidade}, '${property.data}')")).
log("${body}").
delay(1000).
to("jdbc:mysql");
}
});
context.start();
Thread.sleep(20000);
context.stop();
}
private static MysqlConnectionPoolDataSource criaDataSource() {
MysqlConnectionPoolDataSource mysqlDs = new MysqlConnectionPoolDataSource();
mysqlDs.setDatabaseName("camel");
mysqlDs.setServerName("localhost");
mysqlDs.setPort(3306);
mysqlDs.setUser("root");
mysqlDs.setPassword("Olavo1993");
return mysqlDs;
}
}
Baixei recentemente a versão mais recente do mysql que é a versão 8.0.21, por isso no pom coloquei o conector da mesma versão
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jdbc</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
Mas também tentei com outras versões mas nenhum funcionou para mim.
Alguém poderia me ajudar?