最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】集成TDEngine到智能电力的Java后台SprintBoot中

Java crifan 219浏览 0评论
折腾:
【记录】研究TDengine用保存时序数据
后,接着可以去尝试TDEngine集成到之前的智能电力的后端中去试试了。
先去看看官网文档:
Java Connector
The Central Repository Search Engine
仓库服务
https://maven.aliyun.com/mvn/search
Maven Repository: com.taosdata.jdbc » taos-jdbcdriver
com.taosdata.jdbc : taos-jdbcdriver – The Central Repository Search Engine
先去给maven的pom.xml中加上配置试试
src/server/xxx/xxx/pom.xml
        <dependency>
                <groupId>com.taosdata.jdbc</groupId>
                <artifactId>taos-jdbcdriver</artifactId>
                <version>1.0.3</version>
        </dependency>
然后去搞清楚,如何获取连接
文档 | 涛思数据
Class.forName("com.taosdata.jdbc.TSDBDriver");
String jdbcUrl = "jdbc:TAOS://127.0.0.1:6030/log?user=root&password=taosdata";
Connection conn = DriverManager.getConnection(jdbcUrl);
不知道这部分代码,放到哪里。
搜jdbc找到
src/server/xxx/xxx/src/main/resources/application.properties
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/xxx?useUnicode=yes&characterEncoding=UTF-8
估计是这里去配置的?
此处对于taos的服务器的密码,找了下,之前好像也没设置过
估计是默认的密码?
那Mac本地尝试用mysql数据库工具去连接这个taos试试?看看能否连上
结果:
Connection failed!

Unable to connect to host x.x.x.x, or the request timed out.
Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).
MySQL said: Can't connect to MySQL server on ‘x.x.x.x' (4)
连不上
去代码中配置:
spring.datasource.url=jdbc:TAOS://x.x.x.x:6030/ie104
spring.datasource.username=root
spring.datasource.password=taosdata
运行代码试试
尝试登录服务器去看看是否有libtaos.so
结果此处有其他问题:
【已解决】Mac中iTerm2用ssh登录服务器报错:Permissions 0644 for .ssh/id_rsa  are too open
去看看
[[email protected] ~]# ll /usr/lib
总用量 116
...
lrwxrwxrwx   1 root root    21 2月  29 15:55 libtaos.so -> /usr/lib/libtaos.so.1
lrwxrwxrwx   1 root root    41 2月  29 15:55 libtaos.so.1 -> /usr/local/taos/driver/libtaos.so.1.6.5.5
...
是有libtaos.so
后来看到了:
Using connection pool
HikariCP 或Druid
以及:
Integrated with framework
去看看:
TDengine/tests/examples/JDBC/SpringJdbcTemplate at develop · taosdata/TDengine
TDengine/tests/examples/JDBC/springbootdemo at develop · taosdata/TDengine
我之前写的,是类似的写法。不过需要再去确认参数
此处
spring.datasource.druid.xxx
不是很清楚,此处应该是没用druid,所以暂时不去添加这些配置。
以及也没用mybatis,所以先用
src/server/xxx/xxx/src/main/resources/application.properties
logging.config=src/main/resources/log4j2.xml


spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=com.crifan.xxx.MySQL55DialectUtf8mb4
# spring.datasource.connection-init-sql="SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;"
# spring.datasource.connection-init-sql=SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
# spring.datasource.hikari.connection-init-sql=SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';


# spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/xxx?useUnicode=yes&characterEncoding=UTF-8
# spring.datasource.username=xxx
# spring.datasource.password=sepwd


# datasource config
spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
spring.datasource.url=jdbc:TAOS://x.x.x.x:6030/ie104
spring.datasource.username=root
spring.datasource.password=taosdata
看看效果。
[email protected]  ~/dev/dev_root/projects/xxx/src/server/xxx/xxx   master ●  mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.crifan:xxx >-------------------
[INFO] Building xxx 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) > test-compile @ xxx >>>
Downloading from central: https://repo.maven.apache.org/maven2/com/taosdata/jdbc/taos-jdbcdriver/1.0.3/taos-jdbcdriver-1.0.3.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/taosdata/jdbc/taos-jdbcdriver/1.0.3/taos-jdbcdriver-1.0.3.pom (6.7 kB at 1.7 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.2/commons-logging-1.1.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.2/commons-logging-1.1.2.pom (18 kB at 5.4 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/taosdata/jdbc/taos-jdbcdriver/1.0.3/taos-jdbcdriver-1.0.3.jar
Downloading from central: https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.2/commons-logging-1.1.2.jar
。。。
会触发去下载taos的包
继续:
Downloaded from central: https://repo.maven.apache.org/maven2/com/taosdata/jdbc/taos-jdbcdriver/1.0.3/taos-jdbcdriver-1.0.3.jar (74 kB at 5.9 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.2/commons-logging-1.1.2.jar (62 kB at 4.4 kB/s)
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ xxx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ xxx ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ xxx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/crifan/dev/dev_root/projects/xxx/src/server/xxx/xxx/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ xxx ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) < test-compile @ xxx <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) @ xxx ---
[INFO] Attaching agents: []


  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::        (v2.2.2.RELEASE)


2020-03-25 20:48:48,986 INFO  StartupInfoLogger.java:55 - Starting AccessingDataMysqlApplication on licrifandeMacBook-Pro.local with PID 49512 (/Users/crifan/dev/dev_root/projects/xxx/src/server/xxx/xxx/target/classes started by crifan in /Users/crifan/dev/dev_root/projects/xxx/src/server/xxx/xxx)
2020-03-25 20:48:48,993 INFO  SpringApplication.java:651 - No active profile set, falling back to default profiles: default
2020-03-25 20:48:49,245 INFO  DeferredLog.java:225 - The Class-Path manifest attribute in /Users/crifan/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jaxb-runtime-2.3.2.jar referenced one or more files that do not exist: file:/Users/crifan/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.xml.bind-api-2.3.2.jar,file:/Users/crifan/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/txw2-2.3.2.jar,file:/Users/crifan/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/istack-commons-runtime-3.0.8.jar,file:/Users/crifan/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/stax-ex-1.8.1.jar,file:/Users/crifan/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/FastInfoset-1.2.16.jar,file:/Users/crifan/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.activation-api-1.2.1.jar
2020-03-25 20:48:49,270 INFO  DeferredLog.java:225 - Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-03-25 20:48:49,276 INFO  DeferredLog.java:225 - For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-03-25 20:48:51,978 INFO  RepositoryConfigurationDelegate.java:127 - Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-25 20:48:52,306 INFO  RepositoryConfigurationDelegate.java:187 - Finished Spring Data repository scanning in 286ms. Found 1 JPA repository interfaces.
2020-03-25 20:48:53,082 INFO  PostProcessorRegistrationDelegate.java:330 - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-25 20:48:53,803 INFO  TomcatWebServer.java:92 - Tomcat initialized with port(s): 8080 (http)
2020-03-25 20:48:53,819 INFO  DirectJDKLog.java:173 - Initializing ProtocolHandler ["http-nio-8080"]
2020-03-25 20:48:53,821 INFO  DirectJDKLog.java:173 - Starting service [Tomcat]
2020-03-25 20:48:53,821 INFO  DirectJDKLog.java:173 - Starting Servlet engine: [Apache Tomcat/9.0.29]
2020-03-25 20:48:54,137 INFO  DirectJDKLog.java:173 - Initializing Spring embedded WebApplicationContext
2020-03-25 20:48:54,140 INFO  ServletWebServerApplicationContext.java:284 - Root WebApplicationContext: initialization completed in 4863 ms
2020-03-25 20:48:54,644 INFO  Version.java:46 - HHH000412: Hibernate Core {5.4.9.Final}
2020-03-25 20:48:55,280 INFO  JavaReflectionManager.java:49 - HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-03-25 20:48:55,724 INFO  HikariDataSource.java:110 - HikariPool-1 - Starting...
然后报错了:
【未解决】Mac本地测试远程服务器中taos报错:java.lang.UnsatisfiedLinkError no taos in java.library.path

转载请注明:在路上 » 【未解决】集成TDEngine到智能电力的Java后台SprintBoot中

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
86 queries in 0.113 seconds, using 20.69MB memory