问:
Docker, Springboot and Mysql : com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
I try to run a Springboot app with mysql connection on Docker. Without docker, it works well. But when I try to deploy on a container, I have com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure.
I use this docker-compose:

```<code>version: '3'
services:
  nginx:
   container_name: nginx
   image: nginx:latest
   restart: always
   ports:
   - 80:80
   - 443:443
   volumes:
   - ./nginx/conf.d:/etc/nginx/conf.d
   depends_on:
   - spring-boot-app

  mysql:
   container_name: mysql
   image: mysql:latest
   environment:
    MYSQL_ROOT_PASSWORD: "rootpass"
    MYSQL_DATABASE: "db"
    MYSQL_USER: "user"
    MYSQL_PASSWORD: "pass"
   ports:
   - "1306:3306"
   volumes:
   - ./data/:/var/lib/mysql
   networks:
   - mysql-db
   restart: always

  spring-boot-app:
    container_name: spring-boot-app
    image: spring-boot-app
    build:
      context: ./spring-boot-app
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    depends_on:
      - mysql
    networks:
      - mysql-db
    restart: always

networks:
  mysql-db:
      driver: bridge
</code>```

Here is the Dockerfile for springboot app:

```<code>FROM openjdk:11
COPY target/spring-boot-app.jar /spring-boot-app/spring-boot-app.jar
ENTRYPOINT [ "java", "-jar", "-Dspring.profiles.active=prod","/spring-boot-app/spring-boot-app.jar" ]
</code>```

And finally, here is application.properties:

```<code>spring.datasource.url = jdbc:mysql://mysql:1306/db
spring.datasource.username = user
spring.datasource.password = pass

# Show or not log for each sql query
spring.jpa.show-sql = true

# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update

# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager)

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

server.port=8080
</code>```

I don't think this is a port problem because i tried to set mysql to default port (3306), and it still doesn't work.

If it can help, here is docker ps :

```<code>CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                  PORTS                                      NAMES
08ea16361c61        nginx:latest        "nginx -g 'daemon of…"   1 second ago        Up Less than a second   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   nginx
52ef8d5c2127        spring-boot-app     "java -jar -Dspring.…"   3 seconds ago       Up 1 second             0.0.0.0:8080->8080/tcp                     spring-boot-app
7bbcdc1fae3c        mysql:latest        "docker-entrypoint.s…"   4 seconds ago       Up 3 seconds            33060/tcp, 0.0.0.0:1306->3306/tcp          mysql
</code>```

Edit : full stacktrace :

```ubuntu@ubuntu:~/Documents/SpringBoot$ docker-compose up
Creating network "springboot_mysql-db" with driver "bridge"
Creating mysql ... done
Creating spring-boot-app ... done
Attaching to mysql, spring-boot-app
mysql              | 2019-05-27T21:50:19.645920Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
mysql              | 2019-05-27T21:50:19.645986Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 1
mysql              | 2019-05-27T21:50:20.451523Z 0 [System] [MY-010229] [Server] Starting crash recovery...
mysql              | 2019-05-27T21:50:20.466040Z 0 [System] [MY-010232] [Server] Crash recovery finished.
mysql              | 2019-05-27T21:50:20.544487Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql              | 2019-05-27T21:50:20.551894Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql              | 2019-05-27T21:50:20.584210Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.16'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
mysql              | 2019-05-27T21:50:20.682338Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
spring-boot-app    |
spring-boot-app    |   .   ____          _            __ _ _
spring-boot-app    |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
spring-boot-app    | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
spring-boot-app    |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
spring-boot-app    |   '  |____| .__|_| |_|_| |_\__, | / / / /
spring-boot-app    |  =========|_|==============|___/=/_/_/_/
spring-boot-app    |  :: Spring Boot ::        (v2.1.5.RELEASE)
spring-boot-app    |
spring-boot-app    | 2019-05-27 21:50:22.884  INFO 1 --- [           main] com.jv.demo.DemoApplication              : Starting DemoApplication v0.0.1-SNAPSHOT on c69469fd7461 with PID 1 (/spring-boot-app/spring-boot-app.jar started by root in /)
spring-boot-app    | 2019-05-27 21:50:22.903  INFO 1 --- [           main] com.jv.demo.DemoApplication              : The following profiles are active: prod
spring-boot-app    | 2019-05-27 21:50:25.152  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
spring-boot-app    | 2019-05-27 21:50:25.378  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 205ms. Found 1 repository interfaces.
spring-boot-app    | 2019-05-27 21:50:26.313  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$e43b97d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
spring-boot-app    | 2019-05-27 21:50:27.043  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
spring-boot-app    | 2019-05-27 21:50:27.195  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
spring-boot-app    | 2019-05-27 21:50:27.196  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.19]
spring-boot-app    | 2019-05-27 21:50:27.472  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
spring-boot-app    | 2019-05-27 21:50:27.472  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4316 ms
spring-boot-app    | 2019-05-27 21:50:27.928  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
spring-boot-app    | 2019-05-27 21:50:29.226 ERROR 1 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.
spring-boot-app    |
spring-boot-app    | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
spring-boot-app    |
spring-boot-app    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
spring-boot-app    |    at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:73) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:142) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:113) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$2d1a7bec.CGLIB$jpaVendorAdapter$5(<generated>) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$2d1a7bec$$FastClassBySpringCGLIB$$cb57d9da.invoke(<generated>) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$2d1a7bec.jpaVendorAdapter(<generated>) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
spring-boot-app    |    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
spring-boot-app    |    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1168) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1168) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at com.jv.demo.DemoApplication.main(DemoApplication.java:10) ~[classes!/:0.0.1-SNAPSHOT]
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
spring-boot-app    |    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
spring-boot-app    |    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]
spring-boot-app    |    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]
spring-boot-app    |    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]
spring-boot-app    |    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]
spring-boot-app    | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
spring-boot-app    |
spring-boot-app    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
spring-boot-app    |    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
spring-boot-app    |    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.NativeSession.connect(NativeSession.java:152) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    ... 84 common frames omitted
spring-boot-app    | Caused by: java.net.ConnectException: Connection refused (Connection refused)
spring-boot-app    |    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
spring-boot-app    |    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[na:na]
spring-boot-app    |    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) ~[na:na]
spring-boot-app    |    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) ~[na:na]
spring-boot-app    |    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403) ~[na:na]
spring-boot-app    |    at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na]
spring-boot-app    |    at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    ... 87 common frames omitted
spring-boot-app    |
spring-boot-app    | 2019-05-27 21:50:29.234  WARN 1 --- [           main] o.s.b.a.orm.jpa.DatabaseLookup           : Unable to determine jdbc url from datasource
spring-boot-app    |
spring-boot-app    | org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
```

答:
there is a difference between networks and links. use links like the one below

```<code>version: '2'
services:
    web:
        build: .
        links:
            - "db:database"
    db:
        image: postgres
</code>```

this switch will add ID and IP address of one docker container in another on. in this way they can connect to each other. for more info check following link.

Body:
I try to run a Springboot app with mysql connection on Docker. Without docker, it works well. But when I try to deploy on a container, I have com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure.
I use this docker-compose:

version: '3'
services:
  nginx:
   container_name: nginx
   image: nginx:latest
   restart: always
   ports:
   - 80:80
   - 443:443
   volumes:
   - ./nginx/conf.d:/etc/nginx/conf.d
   depends_on:
   - spring-boot-app

  mysql:
   container_name: mysql
   image: mysql:latest
   environment:
    MYSQL_ROOT_PASSWORD: "rootpass"
    MYSQL_DATABASE: "db"
    MYSQL_USER: "user"
    MYSQL_PASSWORD: "pass"
   ports:
   - "1306:3306"
   volumes:
   - ./data/:/var/lib/mysql
   networks:
   - mysql-db
   restart: always

  spring-boot-app:
    container_name: spring-boot-app
    image: spring-boot-app
    build:
      context: ./spring-boot-app
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    depends_on:
      - mysql
    networks:
      - mysql-db
    restart: always

networks:
  mysql-db:
      driver: bridge

Here is the Dockerfile for springboot app:

FROM openjdk:11
COPY target/spring-boot-app.jar /spring-boot-app/spring-boot-app.jar
ENTRYPOINT [ "java", "-jar", "-Dspring.profiles.active=prod","/spring-boot-app/spring-boot-app.jar" ]

And finally, here is application.properties:

spring.datasource.url = jdbc:mysql://mysql:1306/db
spring.datasource.username = user
spring.datasource.password = pass

# Show or not log for each sql query
spring.jpa.show-sql = true

# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update

# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager)

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

server.port=8080

I don't think this is a port problem because i tried to set mysql to default port (3306), and it still doesn't work.

If it can help, here is docker ps :

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                  PORTS                                      NAMES
08ea16361c61        nginx:latest        "nginx -g 'daemon of…"   1 second ago        Up Less than a second   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   nginx
52ef8d5c2127        spring-boot-app     "java -jar -Dspring.…"   3 seconds ago       Up 1 second             0.0.0.0:8080->8080/tcp                     spring-boot-app
7bbcdc1fae3c        mysql:latest        "docker-entrypoint.s…"   4 seconds ago       Up 3 seconds            33060/tcp, 0.0.0.0:1306->3306/tcp          mysql

Edit : full stacktrace :

ubuntu@ubuntu:~/Documents/SpringBoot$ docker-compose up
Creating network "springboot_mysql-db" with driver "bridge"
Creating mysql ... done
Creating spring-boot-app ... done
Attaching to mysql, spring-boot-app
mysql              | 2019-05-27T21:50:19.645920Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
mysql              | 2019-05-27T21:50:19.645986Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 1
mysql              | 2019-05-27T21:50:20.451523Z 0 [System] [MY-010229] [Server] Starting crash recovery...
mysql              | 2019-05-27T21:50:20.466040Z 0 [System] [MY-010232] [Server] Crash recovery finished.
mysql              | 2019-05-27T21:50:20.544487Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql              | 2019-05-27T21:50:20.551894Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql              | 2019-05-27T21:50:20.584210Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.16'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
mysql              | 2019-05-27T21:50:20.682338Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
spring-boot-app    |
spring-boot-app    |   .   ____          _            __ _ _
spring-boot-app    |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
spring-boot-app    | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
spring-boot-app    |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
spring-boot-app    |   '  |____| .__|_| |_|_| |_\__, | / / / /
spring-boot-app    |  =========|_|==============|___/=/_/_/_/
spring-boot-app    |  :: Spring Boot ::        (v2.1.5.RELEASE)
spring-boot-app    |
spring-boot-app    | 2019-05-27 21:50:22.884  INFO 1 --- [           main] com.jv.demo.DemoApplication              : Starting DemoApplication v0.0.1-SNAPSHOT on c69469fd7461 with PID 1 (/spring-boot-app/spring-boot-app.jar started by root in /)
spring-boot-app    | 2019-05-27 21:50:22.903  INFO 1 --- [           main] com.jv.demo.DemoApplication              : The following profiles are active: prod
spring-boot-app    | 2019-05-27 21:50:25.152  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
spring-boot-app    | 2019-05-27 21:50:25.378  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 205ms. Found 1 repository interfaces.
spring-boot-app    | 2019-05-27 21:50:26.313  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$e43b97d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
spring-boot-app    | 2019-05-27 21:50:27.043  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
spring-boot-app    | 2019-05-27 21:50:27.195  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
spring-boot-app    | 2019-05-27 21:50:27.196  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.19]
spring-boot-app    | 2019-05-27 21:50:27.472  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
spring-boot-app    | 2019-05-27 21:50:27.472  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4316 ms
spring-boot-app    | 2019-05-27 21:50:27.928  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
spring-boot-app    | 2019-05-27 21:50:29.226 ERROR 1 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.
spring-boot-app    |
spring-boot-app    | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
spring-boot-app    |
spring-boot-app    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
spring-boot-app    |    at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-app    |    at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:73) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:142) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:113) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$2d1a7bec.CGLIB$jpaVendorAdapter$5(<generated>) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$2d1a7bec$$FastClassBySpringCGLIB$$cb57d9da.invoke(<generated>) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$2d1a7bec.jpaVendorAdapter(<generated>) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
spring-boot-app    |    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
spring-boot-app    |    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1168) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1168) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]
spring-boot-app    |    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]
spring-boot-app    |    at com.jv.demo.DemoApplication.main(DemoApplication.java:10) ~[classes!/:0.0.1-SNAPSHOT]
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
spring-boot-app    |    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
spring-boot-app    |    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]
spring-boot-app    |    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]
spring-boot-app    |    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]
spring-boot-app    |    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]
spring-boot-app    | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
spring-boot-app    |
spring-boot-app    | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
spring-boot-app    |    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
spring-boot-app    |    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
spring-boot-app    |    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.NativeSession.connect(NativeSession.java:152) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    ... 84 common frames omitted
spring-boot-app    | Caused by: java.net.ConnectException: Connection refused (Connection refused)
spring-boot-app    |    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
spring-boot-app    |    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[na:na]
spring-boot-app    |    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) ~[na:na]
spring-boot-app    |    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) ~[na:na]
spring-boot-app    |    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403) ~[na:na]
spring-boot-app    |    at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na]
spring-boot-app    |    at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]
spring-boot-app    |    ... 87 common frames omitted
spring-boot-app    |
spring-boot-app    | 2019-05-27 21:50:29.234  WARN 1 --- [           main] o.s.b.a.orm.jpa.DatabaseLookup           : Unable to determine jdbc url from datasource
spring-boot-app    |
spring-boot-app    | org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

Body:
there is a difference between networks and links. use links like the one below

version: '2'
services:
    web:
        build: .
        links:
            - "db:database"
    db:
        image: postgres

this switch will add ID and IP address of one docker container in another on. in this way they can connect to each other. for more info check following link.


来源: stackexchange

问:
XPath not locating element
What is wrong with my path to select the following:

```<code><label class="form-control-label" for="profile_form_state">State</label>
</code>```

Xpath:

```<code>xpath = '//label[ends-with(@for, "_state")]'
</code>```

I am using rspec and capybara

```<code> expect(rendered).to have_xpath(xpath)
</code>```

Error:

```<code>   xmlXPathCompOpEval: function ends-with not found
</code>```

答:
As answered by @har07, XPath 1.0 (which browsers implement) doesn’t have an ends-with but CSS provides an ends-with attribute selector $=

```<code>expect(rendered).to have_css(‘label[for$=“_state”]’)
</code>```

or you can use regex with Capybaras built-in :label selector

```<code>expect(rendered).to have_selector(:label, for: /_state$/)
</code>```

If you really want to stick with XPath over CSS then you can use the xpath gem Capybara uses internally for generating its own XPaths and write

```<code>xpath = XPath.descendant(:label).where(XPath.attr(:for).ends_with('_start'))
expect(rendered).to have_xpath(xpath)
</code>```

ContentLicense: CC BY-SA 4.0

Title: XPath not locating element

Body:
What is wrong with my path to select the following:

State

Xpath:

xpath = '//label[ends-with(@for, "_state")]'

I am using rspec and capybara

 expect(rendered).to have_xpath(xpath)

Error:

   xmlXPathCompOpEval: function ends-with not found

Body:
As answered by @har07, XPath 1.0 (which browsers implement) doesn’t have an ends-with but CSS provides an ends-with attribute selector $=

expect(rendered).to have_css(‘label[for$=“_state”]’)

or you can use regex with Capybaras built-in :label selector

expect(rendered).to have_selector(:label, for: /_state$/)

If you really want to stick with XPath over CSS then you can use the xpath gem Capybara uses internally for generating its own XPaths and write

xpath = XPath.descendant(:label).where(XPath.attr(:for).ends_with('_start'))
expect(rendered).to have_xpath(xpath)


问:
GIT not running at substituted user - /bin/git: /bin/git: cannot execute binary file
I've just installed git on my CentOS 6 (yum install). And I'd like to clone a repository, but keeping in mind that runing GIT as root user is insecure, I try to do it as admin (whose password I don't remember really). Below is a command flow.

```<code>[root@angkor public_html]# runuser -l admin 'git'
/bin/git: /bin/git: cannot execute binary file
[root@angkor public_html]# su - admin git
Last login: Tue May 28 11:00:08 UTC 2019 on pts/0
/bin/git: /bin/git: cannot execute binary file
[root@angkor public_html]# git
usage: git [--version] [--help] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
</code>```

As we can see git starts when I run it as root but some error reported whan I try to run it as admin. Why and how to fix it?

答:
This is expected, unfortunately:

https://bugzilla.redhat.com/show_bug.cgi?id=1245780

Use this instead:

```<code>runuser -l admin -c 'git'
</code>```

Body:
I've just installed git on my CentOS 6 (yum install). And I'd like to clone a repository, but keeping in mind that runing GIT as root user is insecure, I try to do it as admin (whose password I don't remember really). Below is a command flow.

[root@angkor public_html]# runuser -l admin 'git'
/bin/git: /bin/git: cannot execute binary file
[root@angkor public_html]# su - admin git
Last login: Tue May 28 11:00:08 UTC 2019 on pts/0
/bin/git: /bin/git: cannot execute binary file
[root@angkor public_html]# git
usage: git [--version] [--help] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

As we can see git starts when I run it as root but some error reported whan I try to run it as admin. Why and how to fix it?

Body:
This is expected, unfortunately:

https://bugzilla.redhat.com/show_bug.cgi?id=1245780

Use this instead:

runuser -l admin -c 'git'


问:
how to use ngIf to show data if the value exist?
I need to show an error messege  to show on page if the data searched is not existing on database.
should I use ngIf or there is a better method to apply this?
right now once I click with the wrong data searched nothing is happening
products.component.html

```<code><fa (click)="backToHome()" class="arrow" name="chevron-left"></fa>
<h1>جستجو</h1>
<br /><br /><br /><br />
  <div class="search">
    <input class="input" [(ngModel)]="item" required placeholder="جستجو میان محصولات و برندها" />
    <fa class="icon" name="search" (click)="fetchProducts()"></fa>
  </div>
<p>تاریخچه جستجو</p>
<span>{{name}}</span>
<br />
<br />
  <ul>
    <li *ngFor="let product of resultSearch">
        <a href="#">{{product.name}}</a>

    </li>
  </ul>
 <ul *ngIf="products.lenght">
      <li>{{products.name}}</li>
  </ul>

<router-outlet></router-outlet>
</code>```

product.component.ts

```<code>import { ProductsService } from './../products.service';
import { Component, OnInit} from '@angular/core';
import { Router } from '@angular/router';
@Component({
  selector: 'app-search-page',
  templateUrl:'./search-page.component.html',
  styleUrls: ['./search-page.component.scss']
})
export class SearchPageComponent implements OnInit {
  public products=[];
  resultSearch;
  item='';
constructor(
  private ProductsService:ProductsService,
  private _router:Router,
    ) {
      this.ProductsService.getProducts().
      subscribe(data=> {
        this.products=data
      // this.fetchProducts();
      }
        );
   }

 ngOnInit() {
  }
  fetchProducts()
  {
    this.resultSearch=this.products.filter(product => product.name.includes(this.item));
  }
  backToHome()
  {
    this._router.navigate(['/home']);
  }
  getProduct()
  {
    return this.products.filter(product => product.name.includes(this.item));
  }
  condition(){
    let condition = " not found!";
    if(!this.products.length){
      return condition;
    }
  }
}
</code>```

答:
You can try this..</p>

```<code><ul *ngIf="resultSearch.length;else noContent">
    <li *ngFor="let product of resultSearch">
        <a href="#">{{product.name}}</a>
    </li>
  </ul>

<ng-template #noContent>No matching result...</ng-template>
</code>```

Body:
I need to show an error messege  to show on page if the data searched is not existing on database.
should I use ngIf or there is a better method to apply this?
right now once I click with the wrong data searched nothing is happening
products.component.html

<fa (click)="backToHome()" class="arrow" name="chevron-left"></fa>

جستجو

    <input class="input" [(ngModel)]="item" required placeholder="جستجو میان محصولات و برندها" />
    <fa class="icon" name="search" (click)="fetchProducts()"></fa>

تاریخچه جستجو

{{name}}

        {{product.name}}

{{products.name}}

<router-outlet></router-outlet>

product.component.ts

import { ProductsService } from './../products.service';
import { Component, OnInit} from '@angular/core';
import { Router } from '@angular/router';
@Component({
  selector: 'app-search-page',
  templateUrl:'./search-page.component.html',
  styleUrls: ['./search-page.component.scss']
})
export class SearchPageComponent implements OnInit {
  public products=[];
  resultSearch;
  item='';
constructor(
  private ProductsService:ProductsService,
  private _router:Router,
    ) {
      this.ProductsService.getProducts().
      subscribe(data=> {
        this.products=data
      // this.fetchProducts();
      }
        );
   }

 ngOnInit() {
  }
  fetchProducts()
  {
    this.resultSearch=this.products.filter(product => product.name.includes(this.item));
  }
  backToHome()
  {
    this._router.navigate(['/home']);
  }
  getProduct()
  {
    return this.products.filter(product => product.name.includes(this.item));
  }
  condition(){
    let condition = " not found!";
    if(!this.products.length){
      return condition;
    }
  }
}

Body:
You can try this..

<ul *ngIf="resultSearch.length;else noContent">
    <li *ngFor="let product of resultSearch">
        <a href="#">{{product.name}}</a>
    </li>
  </ul>

<ng-template #noContent>No matching result...</ng-template>


问:
How to convert Tensor to Numpy array of same dimension?
I am trying to convert tensor of an image which is of shape(253,223) to numpy array of the same size so that I can plot the image. I have looked at the documentation and they suggested me to use the eval function as

```<code>sess = tf.Session()
with sess.as_default():
   print(type(tf.constant([img1]).eval()))
</code>```

but it throws the error "List of Tensors when single Tensor expected".

Here type(img1) is
<class 'tensorflow.python.framework.ops.Tensor'> and shape is (253, 223) . Using keras

```<code>tf.keras.backend.eval(x)
</code>```

it throws

InvalidArgumentError: Input to DecodeRaw has length 56419 that is not a multiple of 4, the size of float [[{{node DecodeRaw}}]] error.

How can I convert given tensor to numpy array of the same dimension?

答:
Any tensor returned by Session.run or eval is a NumPy array.

```<code>>>> print(type(tf.Session().run(tf.constant([1,2,3]))))
</code>```

Or:

```<code>>>> sess = tf.InteractiveSession()
    print(type(tf.constant([1,2,3]).eval()))
    <class 'numpy.ndarray'>
</code>```

Body:
I am trying to convert tensor of an image which is of shape(253,223) to numpy array of the same size so that I can plot the image. I have looked at the documentation and they suggested me to use the eval function as

sess = tf.Session()
with sess.as_default():
   print(type(tf.constant([img1]).eval()))

but it throws the error "List of Tensors when single Tensor expected".

Here type(img1) is
<class 'tensorflow.python.framework.ops.Tensor'> and shape is (253, 223) . Using keras

tf.keras.backend.eval(x)

it throws

InvalidArgumentError: Input to DecodeRaw has length 56419 that is not a multiple of 4, the size of float [[{{node DecodeRaw}}]] error.

How can I convert given tensor to numpy array of the same dimension?

Body:
Any tensor returned by Session.run or eval is a NumPy array.

>>> print(type(tf.Session().run(tf.constant([1,2,3]))))

Or:

>>> sess = tf.InteractiveSession()
    print(type(tf.constant([1,2,3]).eval()))
    <class 'numpy.ndarray'>


问:
fullcalendar next and prev
Only yesturday I started to use the jquery fullcarlendar plugin. Now What I am trying to do is on clicking the next or prev buttons I am doing a jquery

```<code>$('#element').load('some_url_here')
</code>```

How exactly do I use the next and previous methods to do something like

```<code> $('#calendar').fullCalendar({
    prev: function(){
        $('#calendar').load("events/findbymonth/"+$('#calendar').fullCalendar('getDate').getMonth());
    },
    next: function(){
        $('#calendar').load("events/findbymonth/"+$('#calendar').fullCalendar('getDate').getMonth());
    },
    title: "My Title",
    events: jsonString,
    editable: false,
    disableDragging: true
});
</code>```

All I need for my url is the next month.
Do I have to manually increment the current month for next and decrement for previous?
Is there a "getCurrentMonth()" method which I can call directly?
Something like   $('#calendar').load("events/findbymonth/"+$('#calendar').fullCalendar.getCurrentMonth());

Thanks, guys

答:
Some likely problem is answered here:
jQuery FullCalendar click 'next' event notificatin</p>

ContentLicense: CC BY-SA 2.5

Title: fullcalendar next and prev

Body:
Only yesturday I started to use the jquery fullcarlendar plugin. Now What I am trying to do is on clicking the next or prev buttons I am doing a jquery

$('#element').load('some_url_here')

How exactly do I use the next and previous methods to do something like

 $('#calendar').fullCalendar({
    prev: function(){
        $('#calendar').load("events/findbymonth/"+$('#calendar').fullCalendar('getDate').getMonth());
    },
    next: function(){
        $('#calendar').load("events/findbymonth/"+$('#calendar').fullCalendar('getDate').getMonth());
    },
    title: "My Title",
    events: jsonString,
    editable: false,
    disableDragging: true
});

All I need for my url is the next month.
Do I have to manually increment the current month for next and decrement for previous?
Is there a "getCurrentMonth()" method which I can call directly?
Something like   $('#calendar').load("events/findbymonth/"+$('#calendar').fullCalendar.getCurrentMonth());

Thanks, guys

ContentLicense: CC BY-SA 3.0


问:
Select row based on another row having same id in same table in MySQL
I have a table view T like:

```<code>id | C1   | C2  |
---+------+-----+
1  | pat  | 190 |
1  | pat1 | 191 |
1  | A5   | 302 |
2  | pet  | 190 |
2  | pet1 | 191 |
2  | A5   | 302 |
3  | pit  | 190 |
3  | pit1 | 191 |
3  | A6   | 302 |
</code>```

Would like to get:

```<code>id | C1   | C2  |
---+------+-----+
1  | pat  | 190 |
2  | pet  | 190 |
</code>```

In other words, return id where C2 = 190 where same id elsewhere in table is A5.

Have tried several LEFT JOIN approaches but haven't gotten anywhere. Please help. Thanx.

答:
You need EXISTS:

```<code>select t.*
from tablename t
where c2 = 190
and exists (
  select 1 from tablename where id = t.id and c1 = 'A5'
)
</code>```

See the demo.

Results:

```<code>| id  | C1  | C2  |
| --- | --- | --- |
| 1   | pat | 190 |
| 2   | pet | 190 |
</code>```

Body:
I have a table view T like:

id | C1   | C2  |
---+------+-----+
1  | pat  | 190 |
1  | pat1 | 191 |
1  | A5   | 302 |
2  | pet  | 190 |
2  | pet1 | 191 |
2  | A5   | 302 |
3  | pit  | 190 |
3  | pit1 | 191 |
3  | A6   | 302 |

Would like to get:

id | C1   | C2  |
---+------+-----+
1  | pat  | 190 |
2  | pet  | 190 |

In other words, return id where C2 = 190 where same id elsewhere in table is A5.

Have tried several LEFT JOIN approaches but haven't gotten anywhere. Please help. Thanx.

Body:
You need EXISTS:

select t.*
from tablename t
where c2 = 190
and exists (
  select 1 from tablename where id = t.id and c1 = 'A5'
)

See the demo.

Results:

| id  | C1  | C2  |
| --- | --- | --- |
| 1   | pat | 190 |
| 2   | pet | 190 |


答:
You can use EXISTS to check if a row with c1 = 'A5' exists for an ID.

```<code>SELECT *
       FROM t t1
       WHERE t1.c2 = 190
             AND EXISTS (SELECT *
                                FROM t t2
                                WHERE t2.id = t1.id
                                      AND t2.c1 = 'A5');
</code>```

Title: Select row based on another row having same id in same table in MySQL

Body:
You can use EXISTS to check if a row with c1 = 'A5' exists for an ID.

SELECT *
       FROM t t1
       WHERE t1.c2 = 190
             AND EXISTS (SELECT *
                                FROM t t2
                                WHERE t2.id = t1.id
                                      AND t2.c1 = 'A5');


问:
Found a formula to know how many "child" a tree have if it's a tree child tree
My problem is a little complex to explain because I'm not a english native speaker and I don't know the word in this matter, but I will try to explain it.
If you think you have keyword to help me, don't hesitate, thanks.

So, I was explaining the binary tree concept to a beginner, and I gave him the formula "2^n - 1". So if the binary tree is full and have a depth of 3, there will be "2^3 - 1 = 7" element in the binary tree.

Then the beginner asked "what if there is not only 2 child (left and rigth) but 3 ? What the formula will be ?" (okay, if each element have 3 child, it's not a binary tree anymore, but bear with me, it's for the sake of the argument).

So a procede to found the formula but failed to do so.

I know that the solution is :

n

Ʃ    3^(x-1)

x = 1

but I can't found the "simplified" version, like

n

Ʃ    2^(x-1)

x = 1

give 2^n - 1

Did the formula exist ? Can we have a general formula with 'C' as the number of child the tree have ?

Sorry for my english, and thanks for reading.

答:
The number of nodes C_{m,k} of a complete tree of height k with m-ary fanout is given by the formula

```<code>C_{m,k} = (m^(k+1) - 1) / (m-1);
</code>```

Proof:

Observation: at level i there are precisely m^i nodes in the tree. 'Level' means distance to the root node (consequentially, the root node's level is 0). Therefore,

```<code>C_{m,k} = sum_{i=0..k} ( m^i )
</code>```

The summation is a finite geometric progression ( ie. the quotient between consecutive summation elements is a constant ). The general formula is ...

```<code>C_{m,k} = (m^(k+1) - 1) / (m-1);
</code>```

... which can easily be proven by induction

Body:
The number of nodes C_{m,k} of a complete tree of height k with m-ary fanout is given by the formula

C_{m,k} = (m^(k+1) - 1) / (m-1);

Proof:

Observation: at level i there are precisely m^i nodes in the tree. 'Level' means distance to the root node (consequentially, the root node's level is 0). Therefore,

C_{m,k} = sum_{i=0..k} ( m^i )

The summation is a finite geometric progression ( ie. the quotient between consecutive summation elements is a constant ). The general formula is ...

C_{m,k} = (m^(k+1) - 1) / (m-1);

... which can easily be proven by induction


问:
IdentityServer event for token cleanup
I would like to know if there is an event that fired in the IdentityServer 4 framework when token cleanup job runs?

I have wrapped a third party system into the IdentityServer framework and need to notify the third party system to cleanup user sessions when the tokens in IdentityServer are no longer valid... mostly due to token is expired.

Any suggestions or examples?

Thanks
Greg

答:
For future references, you need to implement IOperationalStoreNotification and include it in the DI

public class MyOperationalStoreNotification : IOperationalStoreNotification
{
    public Task PersistedGrantsRemovedAsync(IEnumerable<PersistedGrant> persistedGrants)
    {
        // ... put your code here
    }
}
```

Title: IdentityServer event for token cleanup


问:
How to get the elevation of each point of KML file
I have specific route, represented by 100 and more points (classic KML file, for example http://dropbox.com/s/4k1bx3fl3p6h3tj/as-sokolov.kml?dl=1). In this case, I don't need to generate route, but just want to get elevation of any points. Is it possible? Thank you.</p>

答:
In this case, you will have to use the Fleet Telematics API to retrieve advanced data (layers). The ADAS_ATTRIB_FC1...5 layer contains curvature, height and slope information for all FC1 to FC5 roads.
https://developer.here.com/documentation/fleet-telematics/dev_guide/topics/here-map-content.html

You can get the layer content, given a bounding box or a polyline.
https://developer.here.com/documentation/fleet-telematics/api-reference.html#operation%2FsearchCorridorUsingGET


问:
Changing json in Reactjs
I have a json file called by fetch request that looks like this:

```<code>[
{
    "type": "1",
    "Info": {
        "id": {
            "Id": "123456"
        },
        "total": 1100000
    }
},
{
    "type": "2",
    "Infos": [
        {
            "id": {
                "Id": "105254"
            },
            "total": 142854739
        },
        {
            "id": {
                "Id": "105255"
            },
            "total": 112854739
        },
        {
            "id": {
                "Id": "105256"
            },
            "total": 132854739
        },
        {
            "id": {
                "Id": "106540"
            },
            "total": 122868818
        }
    ]
}
]
</code>```

I find object with type 1 and add it to object which type 2 by this code :

```<code>  const type1 = Maindata.find(({ type }) => type === '1');
  const MergedData= Maindata.map(item => item.type === '1' ? item : { ...type1, ...item });
</code>```

I want MergedData will be included just the objects of Infos array.How can I do this?when I get console.log(MergedData.length) ,the length of MergedData is 2 but I want the length of MergedData be 4 , the numbers of objects of Infos array.

```<code>class App extends React.Component {
constructor(props) {
    super(props);
    this.state = {
        data: [],
        library: null,
        perPage: 20,
        currentPage: 1,
        maxPage: null,

    }
}
componentDidMount() {
    fetch('/json.bc', {
        method: 'get',
    })
        .then(response => response.text())
        .then(text => {
            const Maindata = JSON.parse(text.replace(/\'/g, '"'))
            const type1  = Maindata.find(({ type }) => type === '1');
            const MergedData= Maindata.map(item => item.type === '1' ? item : { ...type1, ...item });
            const MergedData2 = MergedData.map(item => item.type === '1' ? item : {...item.hotels}); /// Here I write this code to show just the objects of Infoes array///////
            this.setState(state => ({
                ...state,
                data: MergedData2
            }), () => {
                this.reorganiseLibrary()
            })
        }).catch(error => console.error(error))

}

reorganiseLibrary = () => {
    const { perPage, data } = this.state;
    let library = data;
    library = _.chunk(library, perPage);
    this.setState({
        library,
        currentPage: 1,
        maxPage: library.length === 0 ? 1 : library.length
    })
}

// Previous Page
previousPage = event => {
    this.setState({
        currentPage: this.state.currentPage - 1
    })
}
// Next Page
nextPage = event => {
    this.setState({
        currentPage: this.state.currentPage + 1
    })
}

// handle per page
handlePerPage = (evt) =>
    this.setState({
        perPage: evt.target.value
    }, () => this.reorganiseLibrary());

// handle render of library
renderLibrary = () => {
    const { library, currentPage } = this.state;
    if (!library || (library && library.length === 0)) {
        return <div>NOResult</div>
    }
    return library[currentPage - 1].map((item, i) => (
        <div className="Wrapper">{this.renderInfo(item)}</div>
    ))
}

renderInfo(element) {
    let len = element.Infos.length
    for (let i = 0; i < len; i++) {
        return element.Infos[i].total
    }
}

render() {
    const { library, currentPage, perPage, maxPage } = this.state;
    return (
        <div>
            {this.renderLibrary()}
            <ul id="page-numbers">
                <li className="nexprevPage">
                    {currentPage !== 1 && (
                        <button onClick={this.previousPage}><span className="fa-backward"></span></button>
                    )}
                </li>
                <li className="controlsPage activeCnt">{this.state.currentPage}</li>
                <li className="restControls">...</li>
                <li className="controlsPage">{this.state.maxPage}</li>
                <li className="nexprevPage">
                    {(currentPage < maxPage) && (
                        <button onClick={this.nextPage}><span className="fa-forward"></span></button>
                    )}
                </li>
            </ul>
        </div>
    )
}
}
ReactDOM.render(<App />, document.getElementById('Result'))
</code>```

Title: Changing json in Reactjs

Body:
I have a json file called by fetch request that looks like this:

[
{
    "type": "1",
    "Info": {
        "id": {
            "Id": "123456"
        },
        "total": 1100000
    }
},
{
    "type": "2",
    "Infos": [
        {
            "id": {
                "Id": "105254"
            },
            "total": 142854739
        },
        {
            "id": {
                "Id": "105255"
            },
            "total": 112854739
        },
        {
            "id": {
                "Id": "105256"
            },
            "total": 132854739
        },
        {
            "id": {
                "Id": "106540"
            },
            "total": 122868818
        }
    ]
}
]

I find object with type 1 and add it to object which type 2 by this code :

  const type1 = Maindata.find(({ type }) => type === '1');
  const MergedData= Maindata.map(item => item.type === '1' ? item : { ...type1, ...item });

I want MergedData will be included just the objects of Infos array.How can I do this?when I get console.log(MergedData.length) ,the length of MergedData is 2 but I want the length of MergedData be 4 , the numbers of objects of Infos array.

class App extends React.Component {
constructor(props) {
    super(props);
    this.state = {
        data: [],
        library: null,
        perPage: 20,
        currentPage: 1,
        maxPage: null,

    }
}
componentDidMount() {
    fetch('/json.bc', {
        method: 'get',
    })
        .then(response => response.text())
        .then(text => {
            const Maindata = JSON.parse(text.replace(/\'/g, '"'))
            const type1  = Maindata.find(({ type }) => type === '1');
            const MergedData= Maindata.map(item => item.type === '1' ? item : { ...type1, ...item });
            const MergedData2 = MergedData.map(item => item.type === '1' ? item : {...item.hotels}); /// Here I write this code to show just the objects of Infoes array///////
            this.setState(state => ({
                ...state,
                data: MergedData2
            }), () => {
                this.reorganiseLibrary()
            })
        }).catch(error => console.error(error))

}

reorganiseLibrary = () => {
    const { perPage, data } = this.state;
    let library = data;
    library = _.chunk(library, perPage);
    this.setState({
        library,
        currentPage: 1,
        maxPage: library.length === 0 ? 1 : library.length
    })
}

// Previous Page
previousPage = event => {
    this.setState({
        currentPage: this.state.currentPage - 1
    })
}
// Next Page
nextPage = event => {
    this.setState({
        currentPage: this.state.currentPage + 1
    })
}

// handle per page
handlePerPage = (evt) =>
    this.setState({
        perPage: evt.target.value
    }, () => this.reorganiseLibrary());

// handle render of library
renderLibrary = () => {
    const { library, currentPage } = this.state;
    if (!library || (library && library.length === 0)) {
        return
NOResult

    }
    return library[currentPage - 1].map((item, i) => (

{this.renderInfo(item)}

    ))
}

renderInfo(element) {
    let len = element.Infos.length
    for (let i = 0; i < len; i++) {
        return element.Infos[i].total
    }
}

render() {
    const { library, currentPage, perPage, maxPage } = this.state;
    return (

            {this.renderLibrary()}

                    {currentPage !== 1 && (
                        <button onClick={this.previousPage}></button>
                    )}

{this.state.currentPage}

...

{this.state.maxPage}

                    {(currentPage < maxPage) && (
                        <button onClick={this.nextPage}></button>
                    )}

    )
}
}
ReactDOM.render(<App />, document.getElementById('Result'))

Body:
var s = [
{
    "type": "1",
    "Info": {
        "id": {
            "Id": "123456"
        },
        "total": 1100000
    }
},
{
    "type": "2",
    "Infos": [
        {
            "id": {
                "Id": "105254"
            },
            "total": 142854739
        },
        {
            "id": {
                "Id": "105255"
            },
            "total": 112854739
        },
        {
            "id": {
                "Id": "105256"
            },
            "total": 132854739
        },
        {
            "id": {
                "Id": "106540"
            },
            "total": 122868818
        }
    ]
}
]

var m = s.map(i => Object.keys(i).includes('Infos') ? i.Infos : i.Info)
console.log(m)

printed Value - [{"id":{"Id":"123456"},"total":1100000},[{"id":{"Id":"105254"},"total":142854739},{"id":{"Id":"105255"},"total":112854739},{"id":{"Id":"105256"},"total":132854739},{"id":{"Id":"106540"},"total":122868818}]]

You can just write this small code for getting mergedData of info/infos of whole array.

If both the object has 'Info' key in them - you can just write
var m = s.map(i => i.Info)


问:
update a column when multiple records of another columns of same table matches
I have table as below:

```<code>            Input table:
            RequestNumber            TrackName         Date
            -----------------------------------------------------------
            02209                    Middle         2017-05-28 00:00:00
            0263                     Middle         2017-06-29 00:00:00
            0633                     Middle         2017-09-10 00:00:00
            0762                     Back           2017-06-23 00:00:00
            0762                     Front          2017-06-23 00:00:00
            0762                     Middle         2017-06-23 00:00:00
            01839                    Middle         2017-03-09 00:00:00
</code>```

I need to check, if "RequestNumber" and "Date" is same for "TrackName".
if multiple reacords of "RequestNumber" and "Date" matches then I should update the "TrackName" column as "All three" as below
output example (in this example there are 3 records matching)

```<code>            Output table:
            RequestNumber            TrackName         Date
            -----------------------------------------------------------
            02209                    Middle         2017-05-28 00:00:00
            0263                     Middle         2017-06-29 00:00:00
            0633                     Middle         2017-09-10 00:00:00
            0762                     All three      2017-06-23 00:00:00
            01839                    Middle         2017-03-09 00:00:00
</code>```

To get the above desigred output this is the SQL I have tried. Howveer, its updating all TrackName to All three.

```<code>            UPDATE a
            SET a.[TrackName] = 'All three'
            FROM Table1 as a
            INNER JOIN
            (SELECT [RequestNumber], row_number() OVER (ORDER BY [RequestNumber] DESC) as rowNumber
            FROM Table1 ) drRowNumbers ON drRowNumbers.[RequestNumber] = a.[RequestNumber] and drRowNumbers.[Date] = a.[Date]
</code>```

Hope I have explained this correctly. What am I doing worng? Any query to fix this please?

Note: The records are coming dynamically so can not be hardcoded(if any).

Thanks.

答:
Give this a try

step 1 set one of the recs to All Three

```<code>update table1
set TrackName = 'All Three'
where requestnumber in (select requestnumber
from table1
group by requestnumber,[date]
having count(*) = 3)
and trackname = 'Front'
</code>```

step 2 remove the data no longer required

```<code>delete table1
where requestnumber in (select requestnumber
from table1
group by requestnumber,[date]
having count(*) = 3)
and trackname <> 'All Three'
</code>```

Body:
I have table as below:

            Input table:
            RequestNumber            TrackName         Date
            -----------------------------------------------------------
            02209                    Middle         2017-05-28 00:00:00
            0263                     Middle         2017-06-29 00:00:00
            0633                     Middle         2017-09-10 00:00:00
            0762                     Back           2017-06-23 00:00:00
            0762                     Front          2017-06-23 00:00:00
            0762                     Middle         2017-06-23 00:00:00
            01839                    Middle         2017-03-09 00:00:00

I need to check, if "RequestNumber" and "Date" is same for "TrackName".
if multiple reacords of "RequestNumber" and "Date" matches then I should update the "TrackName" column as "All three" as below
output example (in this example there are 3 records matching)

            Output table:
            RequestNumber            TrackName         Date
            -----------------------------------------------------------
            02209                    Middle         2017-05-28 00:00:00
            0263                     Middle         2017-06-29 00:00:00
            0633                     Middle         2017-09-10 00:00:00
            0762                     All three      2017-06-23 00:00:00
            01839                    Middle         2017-03-09 00:00:00

To get the above desigred output this is the SQL I have tried. Howveer, its updating all TrackName to All three.

            UPDATE a
            SET a.[TrackName] = 'All three'
            FROM Table1 as a
            INNER JOIN
            (SELECT [RequestNumber], row_number() OVER (ORDER BY [RequestNumber] DESC) as rowNumber
            FROM Table1 ) drRowNumbers ON drRowNumbers.[RequestNumber] = a.[RequestNumber] and drRowNumbers.[Date] = a.[Date]

Hope I have explained this correctly. What am I doing worng? Any query to fix this please?

Note: The records are coming dynamically so can not be hardcoded(if any).

Thanks.

Body:
Give this a try

step 1 set one of the recs to All Three

update table1
set TrackName = 'All Three'
where requestnumber in (select requestnumber
from table1
group by requestnumber,[date]
having count(*) = 3)
and trackname = 'Front'

step 2 remove the data no longer required

delete table1
where requestnumber in (select requestnumber
from table1
group by requestnumber,[date]
having count(*) = 3)
and trackname <> 'All Three'


问:
Testing a Buildroot external package fails on a defconfig entry
I'm trying to add an br2-external package to a Buildroot build for a sama5d4_xplained board. I'm testing it using the utils/test-pkg utility and with every toolchain it fails on BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y, according to the missing.config file. It's an entry in the sama5d4_xplained_defconfig, which is used in the build.

I attempted to find what does the option mean in the manual and by googling, but any information is nowhere to be found. It doesn't seem to be related to the version of kernel headers installed on my machine, since my headers are 4.15.

The exact command used is:

```<code>./utils/test-pkg -c ../../config/sama5d4_xplained_defconfig -p {package}
</code>```

The sama5d4_xplained_defconfig has the problematic entry:

```<code>BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y
</code>```

logfile content:

```<code>#
# configuration written to /home/bartlomiej/br-test-pkg/br-arm-full-static/.config
#
Value requested for BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9 not in final .config
Requested value:  BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y
Actual value:

Using support/config-fragments/autobuild/br-arm-full-static.config as base
Merging support/config-fragments/minimal.config
Merging ../../config/sama5d4_xplained_defconfig
  GEN     /home/bartlomiej/br-test-pkg/br-arm-full-static/Makefile
#
# configuration written to /home/bartlomiej/br-test-pkg/br-arm-full-static/.config
#
Value requested for BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9 not in final .config
Requested value:  BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y
Actual value:

Using support/config-fragments/autobuild/br-arm-full-static.config as base
Merging support/config-fragments/minimal.config
Merging ../../config/sama5d4_xplained_defconfig
  GEN     /home/bartlomiej/br-test-pkg/br-arm-full-static/Makefile
#
# configuration written to /home/bartlomiej/br-test-pkg/br-arm-full-static/.config
#
Value requested for BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9 not in final .config
Requested value:  BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y
Actual value:
</code>```

What does this entry mean, and what do I do to fix the build problems?

答:
You have to make a configuration file that enables just your package. With recent Buildroot, you can also use test-pkg -p <pkg> without -c option.

test-pkg will do a build-test of one or more packages with a collection of different toolchains (by default, a subset of the toolchains used for the autobuilders). The configuration file you supply with -c is supposed to select the package(s) that you want to test. Any toolchain that does not satisfy the dependencies of those packages will be skipped.

The board defconfigs (like sama5d4_xplained_defconfig) build a toolchain as part of their configuration. This toolchain always differs from the toolchains used in the autobuilders. Therefore, if you supply one of the defconfigs as the -c option, all toolchains will always be skipped.

However, if you are only interested in the sama5d4 Xplained board, there is no real need to use test-pkg to test your package with all toolchains. Just enable the package to a custom configuration.

Body:
I'm trying to add an br2-external package to a Buildroot build for a sama5d4_xplained board. I'm testing it using the utils/test-pkg utility and with every toolchain it fails on BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y, according to the missing.config file. It's an entry in the sama5d4_xplained_defconfig, which is used in the build.

I attempted to find what does the option mean in the manual and by googling, but any information is nowhere to be found. It doesn't seem to be related to the version of kernel headers installed on my machine, since my headers are 4.15.

The exact command used is:

./utils/test-pkg -c ../../config/sama5d4_xplained_defconfig -p {package}

The sama5d4_xplained_defconfig has the problematic entry:

BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y

logfile content:

#
# configuration written to /home/bartlomiej/br-test-pkg/br-arm-full-static/.config
#
Value requested for BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9 not in final .config
Requested value:  BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y
Actual value:

Using support/config-fragments/autobuild/br-arm-full-static.config as base
Merging support/config-fragments/minimal.config
Merging ../../config/sama5d4_xplained_defconfig
  GEN     /home/bartlomiej/br-test-pkg/br-arm-full-static/Makefile
#
# configuration written to /home/bartlomiej/br-test-pkg/br-arm-full-static/.config
#
Value requested for BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9 not in final .config
Requested value:  BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y
Actual value:

Using support/config-fragments/autobuild/br-arm-full-static.config as base
Merging support/config-fragments/minimal.config
Merging ../../config/sama5d4_xplained_defconfig
  GEN     /home/bartlomiej/br-test-pkg/br-arm-full-static/Makefile
#
# configuration written to /home/bartlomiej/br-test-pkg/br-arm-full-static/.config
#
Value requested for BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9 not in final .config
Requested value:  BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y
Actual value:

What does this entry mean, and what do I do to fix the build problems?


问:
Why is there still a conflict between prototype and jquery?
I've already read about how to load prototype and jquery together but these techniques are not solving the problem.

I load jquery then this file (http://music.glumbo.com/izzyFeedback.js) and then prototype.

I've wrapped parts that use $ in izzyFeedback.js in

```<code>(function($) {

})(jQuery);
</code>```

but this does not work. If I comment out the prototype load then it works correctly.

答:
You need to use jQuery.noConflict() to revert $ back to whatever had it first.

Then, you need to use jQuery instead of $ for the jQuery function or use what you assign jQuery.noConflict() to.

Body:
I've already read about how to load prototype and jquery together but these techniques are not solving the problem.

I load jquery then this file (http://music.glumbo.com/izzyFeedback.js) and then prototype.

I've wrapped parts that use $ in izzyFeedback.js in

(function($) {

})(jQuery);

but this does not work. If I comment out the prototype load then it works correctly.


问:
Is possible to create instance of Location?
When I type window in console. console show that window is instance of Window. Is it possible to create new window object using new Window(). I tried it but it throwing error TypeError: Illegal constructor

My Question is related to Location object. can I create a new object using Location?
I need it so that I can apply method available on location object to  my links.

I was trying to access Location object but no success.

I am using Chrome console.

答:
Depending on what you need your Location to do you can.
I used below code to create a Location for a unit test.

```<code>const windowLocation: Location = {
    host: 'localhost:4200',
    protocol: 'http:',
    ancestorOrigins: null,
    hash: null,
    href: null,
    hostname: null,
    origin: null,
    pathname: null,
    port: null,
    search: null,
    assign: null,
    reload: null,
    replace: null,
};
</code>```

Body:
Depending on what you need your Location to do you can.
I used below code to create a Location for a unit test.

const windowLocation: Location = {
    host: 'localhost:4200',
    protocol: 'http:',
    ancestorOrigins: null,
    hash: null,
    href: null,
    hostname: null,
    origin: null,
    pathname: null,
    port: null,
    search: null,
    assign: null,
    reload: null,
    replace: null,
};


问:
TextField uppercase and lowercase validation
I am working on textfields validations and getting confused how to validate textfield must contain at least 1 character from all of the following categories:
English uppercase characters (A - Z).
English lowercase characters (a - z).</p>

答:
Simple extension accepts any CharacterSet to check:

```<code>extension String {
    func hasCharacter(in characterSet: CharacterSet) -> Bool {
        return rangeOfCharacter(from: characterSet) != nil
    }
}
</code>```

usage:

```<code>"aBc".hasCharacter(in: .lowercaseLetters)
"aBc".hasCharacter(in: .uppercaseLetters)
</code>```

Body:
Simple extension accepts any CharacterSet to check:

extension String {
    func hasCharacter(in characterSet: CharacterSet) -> Bool {
        return rangeOfCharacter(from: characterSet) != nil
    }
}

usage:

"aBc".hasCharacter(in: .lowercaseLetters)
"aBc".hasCharacter(in: .uppercaseLetters)