问:
Spring boot data jpa multiple datasources entityManagerFactory error
I want to use two databases with Spring Boot. Here the code:

first db config

```<code>@Configuration
@EnableAutoConfiguration
@EnableJpaRepositories(
        basePackages = {"net.elyland.pipe.repositories.router"},
        entityManagerFactoryRef = "routerEntityManagerFactory",
        transactionManagerRef = "routerTransactionManager")
@EnableTransactionManagement
@PropertySource("classpath:application.properties")
@ComponentScan(basePackages = {"net.elyland.pipe.domain.router"})
public class RouterRepositoryConfiguration {

    @Bean(name = "routerDataSource")
    @ConfigurationProperties(prefix = "router.datasource")
    public DataSource routerDataSource() {
        return DataSourceBuilder
                .create()
                .build();
    }

    @PersistenceContext(unitName = "routerPU")
    @Bean(name = "routerEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean routerEntityManagerFactory(EntityManagerFactoryBuilder builder, @Qualifier("routerDataSource")DataSource routerDataSource) {
        return builder
                .dataSource(routerDataSource)
                .properties(hibernateProperties())
                .packages(Ip.class, Net.class, Provider.class, QueueRule.class, QueueType.class,RemoteIp.class,Subnet.class,TrafficQueue.class)
                .persistenceUnit("routerPU")
                .build();
    }

    @Bean(name = "routerTransactionManager")
    public PlatformTransactionManager mysqlTransactionManager(@Qualifier("routerEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
        return new JpaTransactionManager(entityManagerFactory);
    }

    private Map hibernateProperties() {

        Resource resource = new ClassPathResource("routerHibernate.properties");

        try {
            Properties properties = PropertiesLoaderUtils.loadProperties(resource);

            return properties.entrySet().stream()
                    .collect(Collectors.toMap(
                            e -> e.getKey().toString(),
                            e -> e.getValue())
                    );
        } catch (IOException e) {
            return new HashMap();
        }
    }
}
</code>```

Second db config:

```<code>@Configuration
@EnableAutoConfiguration
@EnableJpaRepositories(
        basePackageClasses = {SshUser.class, User.class, Role.class},
        basePackages = {"net.elyland.pipe.domain.admin"},
        entityManagerFactoryRef = "adminEntityManager" ,
        transactionManagerRef = "adminTransactionManager"
        )
@EnableTransactionManagement
@PropertySource({ "classpath:application.properties" })
public class AdminRepositoryConfiguration {

    @Primary
    @Bean(name = "adminDataSource")
    @ConfigurationProperties(prefix = "admin.datasource")

    public DataSource adminDataSource() {
        System.out.println("Create datasource Admin");
        return DataSourceBuilder
                .create()
                .build();
    }

    @Primary
    @Bean(name = "adminEntityManager")
    public LocalContainerEntityManagerFactoryBean adminEntityManager(EntityManagerFactoryBuilder builder, @Qualifier("adminDataSource") DataSource adminDataSource) {
        return builder
                .dataSource(adminDataSource)
                .properties(hibernateProperties())
                .packages(User.class, LocalIp.class, CommandLog.class, PipeSize.class, Role.class,Rule.class,Server.class,SshUser.class)
                .persistenceUnit("adminPU")
                .build();
    }

    @Primary
    @Bean(name = "adminTransactionManager")
    public PlatformTransactionManager adminTransactionManager(@Qualifier("adminEntityManager") EntityManagerFactory entityManagerFactory) {
        return new JpaTransactionManager(entityManagerFactory);
    }

    private Map hibernateProperties() {

        Resource resource = new ClassPathResource("hibernate.properties");

        try {
            Properties properties = PropertiesLoaderUtils.loadProperties(resource);

            return properties.entrySet().stream()
                    .collect(Collectors.toMap(
                            e -> e.getKey().toString(),
                            e -> e.getValue())
                    );
        } catch (IOException e) {
            return new HashMap();
        }
    }
}
</code>```

Repository 1:

```<code>@Repository
@Transactional("adminTransactionManager")
public interface SshUserRepository extends JpaRepository<SshUser, Integer> {
    SshUser findByUsername(String username);
}
</code>```

Repository 2:

```<code>@Repository
@Transactional("routerTransactionManager")
public interface SubnetRepository extends JpaRepository<Subnet, Integer> {
    public Subnet findByAddress(Integer address);
    public Subnet findByMask(Integer mask);
}
</code>```

properties file:

```<code>admin.datasource.url= jdbc:mysql://192.168.10.3:3306/pipe?autoReconnect=true&useSSL=false
admin.datasource.username=user
admin.datasource.password=pass
admin.datasource.driverClassName=com.mysql.jdbc.Driver

router.datasource.url= jdbc:mysql://192.168.10.3:3306/router?autoReconnect=true&useSSL=false
router.datasource.username=user
router.datasource.password=pass
router.datasource.driverClassName=com.mysql.jdbc.Driver
</code>```

hibernate.properties:

```<code>#spring.jpa.show-sql = true
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=create-drop
</code>```

At the start I have this error:

```<code>***************************
APPLICATION FAILED TO START
***************************

Description:

Field userRepository in net.elyland.pipe.services.UserDetailsServiceImpl required a bean named 'entityManagerFactory' that could not be found.

Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.
</code>```

Here the full log:

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

2017-07-07 18:52:18.774  INFO 11870 --- [           main] n.e.pipe.SpringBootMvcJspApplication     : Starting SpringBootMvcJspApplication on adm-imaterynko with PID 11870 (/home/imaterynko/SVN/sysadm/javawebdev/pipe/target/classes started by imaterynko in /home/imaterynko/SVN/sysadm/javawebdev/pipe)
2017-07-07 18:52:18.780  INFO 11870 --- [           main] n.e.pipe.SpringBootMvcJspApplication     : No active profile set, falling back to default profiles: default
2017-07-07 18:52:18.859  INFO 11870 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6a472554: startup date [Fri Jul 07 18:52:18 EEST 2017]; root of context hierarchy
2017-07-07 18:52:20.485  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'remoteIpRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.487  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'providerRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.488  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'netRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.491  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'queueTypeRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.492  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'ipRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.494  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'subnetRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.497  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'queueRuleRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.504  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'trafficQueueRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:21.046  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration' of type [class org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.110  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'validator' of type [class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.158  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [class org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$ee2486b5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.170  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [class org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.172  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@678040b3' of type [class org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.180  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [class org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$12f92967] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.193  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [class org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.203  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$5576be7b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.537  INFO 11870 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-07-07 18:52:21.551  INFO 11870 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-07-07 18:52:21.552  INFO 11870 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.11
2017-07-07 18:52:22.039  INFO 11870 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2017-07-07 18:52:22.042  INFO 11870 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-07-07 18:52:22.042  INFO 11870 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3185 ms
2017-07-07 18:52:22.239  INFO 11870 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-07-07 18:52:22.240  INFO 11870 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2017-07-07 18:52:22.241  INFO 11870 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Filter characterEncodingFilter was not registered (possibly already registered?)
2017-07-07 18:52:22.241  INFO 11870 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
Create datasource Admin
2017-07-07 18:52:22.894  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'adminPU'
2017-07-07 18:52:22.912  INFO 11870 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: adminPU
    ...]
2017-07-07 18:52:22.971  INFO 11870 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.11.Final}
2017-07-07 18:52:22.973  INFO 11870 --- [           main] org.hibernate.cfg.Environment            : HHH000205: Loaded properties from resource hibernate.properties: {hibernate.dialect=org.hibernate.dialect.MySQL5Dialect, hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=create-drop}
2017-07-07 18:52:22.974  INFO 11870 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-07-07 18:52:23.007  INFO 11870 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-07-07 18:52:23.210  INFO 11870 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-07-07 18:52:23.673  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-07-07 18:52:23.685 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table command_log drop foreign key FKo5wo2sqahur6v6uym1t2sjken
2017-07-07 18:52:23.685 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.command_log' doesn't exist
2017-07-07 18:52:23.688 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table host drop foreign key FK9hlhx55t325whiraf8newuxcv
2017-07-07 18:52:23.688 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.host' doesn't exist
2017-07-07 18:52:23.689 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table rule drop foreign key FKeuk4g8c1yhpjno3suq3syen02
2017-07-07 18:52:23.690 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.rule' doesn't exist
2017-07-07 18:52:23.691 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table rule drop foreign key FKtria2gmd5ghsirwucl003p935
2017-07-07 18:52:23.691 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.rule' doesn't exist
2017-07-07 18:52:23.693 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table rule drop foreign key FKsoy6c2wf2ahd7y2awnfabuxkc
2017-07-07 18:52:23.694 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.rule' doesn't exist
2017-07-07 18:52:23.695 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table user drop foreign key FKn82ha3ccdebhokx3a8fgdqeyy
2017-07-07 18:52:23.695 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.user' doesn't exist
2017-07-07 18:52:24.183  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2017-07-07 18:52:24.238  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'adminPU'
2017-07-07 18:52:24.300  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'routerPU'
2017-07-07 18:52:24.301  INFO 11870 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: routerPU
    ...]
2017-07-07 18:52:24.386  INFO 11870 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-07-07 18:52:24.476  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-07-07 18:52:24.478 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table ip drop foreign key FKnunykfm5kyqpk69fu78rm690t
2017-07-07 18:52:24.478 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.ip' doesn't exist
2017-07-07 18:52:24.479 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table ip drop foreign key FK3fkkinqulfhgjo6c7gu8ptu8f
2017-07-07 18:52:24.479 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.ip' doesn't exist
2017-07-07 18:52:24.481 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table ip drop foreign key FK4txj00furhr0boqimj1s0loa1
2017-07-07 18:52:24.481 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.ip' doesn't exist
2017-07-07 18:52:24.483 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table queue_rule drop foreign key FK5bm4nnopngcrglm6od8m97yhh
2017-07-07 18:52:24.483 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.queue_rule' doesn't exist
2017-07-07 18:52:24.485 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table queue_rule drop foreign key FKohmfk4krumgcaa75kxnfxcwfv
2017-07-07 18:52:24.485 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.queue_rule' doesn't exist
2017-07-07 18:52:24.486 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table queue_rule drop foreign key FKtc36dnb4iulun0yn72wqrybf4
2017-07-07 18:52:24.486 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.queue_rule' doesn't exist
2017-07-07 18:52:24.487 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table queue_rule drop foreign key FK3t8l9ho5h9g7soqrk94h3van0
2017-07-07 18:52:24.487 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.queue_rule' doesn't exist
2017-07-07 18:52:25.003  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2017-07-07 18:52:25.007  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'routerPU'
2017-07-07 18:52:25.124  WARN 11870 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfiguration': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsServiceImpl': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#693f2213' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#693f2213': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2017-07-07 18:52:25.124  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'routerPU'
2017-07-07 18:52:25.124  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-07-07 18:52:25.523  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2017-07-07 18:52:25.526  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'adminPU'
2017-07-07 18:52:25.526  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-07-07 18:52:25.920  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2017-07-07 18:52:25.925  WARN 11870 --- [           main] o.s.boot.SpringApplication               : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available)
2017-07-07 18:52:25.985 ERROR 11870 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

Field userRepository in net.elyland.pipe.services.UserDetailsServiceImpl required a bean named 'entityManagerFactory' that could not be found.

Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.
```

Can somebody say what's wrong?
Thanks.

答:
When having multiple data sources in spring-boot, use separate class for each data source to for the sake of readability of code as well as to avoid such errors (Consider defining a bean named 'entityManagerFactory' in your configuration.)

In case of single datasource in Application, spring boot would have created a default entityManagerFactory bean for it. But on having multiple data sources we need to define entityManagerFactory & transactionManager explicitly for each of them.

For example, you have to use two data sources in your app ds1 & ds2, create beans like below :

Bean for ds1

```<code>@Configuration
@Import(SomePrimaryConfig.class)
@EnableJpaRepositories(
    basePackages = "com.ds1.repos",
    entityManagerFactoryRef = "ds1EMF",
    transactionManagerRef = "ds1TM")
public class DataSource1 {

@Bean
@ConfigurationProperties("ds1.datasource")
public DataSource ds1DataSource() {
    DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
    // other datasource details to set
    return dataSourceBuilder.build();
}

@Bean
LocalContainerEntityManagerFactoryBean ds1EMF(DataSource ds1DataSource) {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(ds1DataSource);
    entityManagerFactoryBean.setPackagesToScan("com.ds1.models");
    //entityManagerFactoryBean.setJpaProperties(jpaProperties);
    return entityManagerFactoryBean;
}

@Bean
JpaTransactionManager ds1TM(EntityManagerFactory ds1EMF) {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(ds1EMF);
    return transactionManager;
 }
}
</code>```

Bean for ds2

```<code>@Configuration
@Import(SomePrimaryConfig.class)
@EnableJpaRepositories(
    basePackages = "com.ds2.repos",
    entityManagerFactoryRef = "ds2EMF",
    transactionManagerRef = "ds2TM")
public class DataSource2 {

@Bean
@ConfigurationProperties("ds2.datasource")
public DataSource ds1DataSource() {
    DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
    // other datasource details to set
    return dataSourceBuilder.build();
}

@Bean
LocalContainerEntityManagerFactoryBean ds2EMF(DataSource ds2DataSource) {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(ds2DataSource);
    entityManagerFactoryBean.setPackagesToScan("com.ds2.models");
    //entityManagerFactoryBean.setJpaProperties(jpaProperties);
    return entityManagerFactoryBean;
}

@Bean
JpaTransactionManager ds2TM(EntityManagerFactory ds2EMF) {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(ds2EMF);
    return transactionManager;
 }
}
</code>```

Body:
I want to use two databases with Spring Boot. Here the code:

first db config

@Configuration
@EnableAutoConfiguration
@EnableJpaRepositories(
        basePackages = {"net.elyland.pipe.repositories.router"},
        entityManagerFactoryRef = "routerEntityManagerFactory",
        transactionManagerRef = "routerTransactionManager")
@EnableTransactionManagement
@PropertySource("classpath:application.properties")
@ComponentScan(basePackages = {"net.elyland.pipe.domain.router"})
public class RouterRepositoryConfiguration {

    @Bean(name = "routerDataSource")
    @ConfigurationProperties(prefix = "router.datasource")
    public DataSource routerDataSource() {
        return DataSourceBuilder
                .create()
                .build();
    }

    @PersistenceContext(unitName = "routerPU")
    @Bean(name = "routerEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean routerEntityManagerFactory(EntityManagerFactoryBuilder builder, @Qualifier("routerDataSource")DataSource routerDataSource) {
        return builder
                .dataSource(routerDataSource)
                .properties(hibernateProperties())
                .packages(Ip.class, Net.class, Provider.class, QueueRule.class, QueueType.class,RemoteIp.class,Subnet.class,TrafficQueue.class)
                .persistenceUnit("routerPU")
                .build();
    }

    @Bean(name = "routerTransactionManager")
    public PlatformTransactionManager mysqlTransactionManager(@Qualifier("routerEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
        return new JpaTransactionManager(entityManagerFactory);
    }

    private Map hibernateProperties() {

        Resource resource = new ClassPathResource("routerHibernate.properties");

        try {
            Properties properties = PropertiesLoaderUtils.loadProperties(resource);

            return properties.entrySet().stream()
                    .collect(Collectors.toMap(
                            e -> e.getKey().toString(),
                            e -> e.getValue())
                    );
        } catch (IOException e) {
            return new HashMap();
        }
    }
}

Second db config:

@Configuration
@EnableAutoConfiguration
@EnableJpaRepositories(
        basePackageClasses = {SshUser.class, User.class, Role.class},
        basePackages = {"net.elyland.pipe.domain.admin"},
        entityManagerFactoryRef = "adminEntityManager" ,
        transactionManagerRef = "adminTransactionManager"
        )
@EnableTransactionManagement
@PropertySource({ "classpath:application.properties" })
public class AdminRepositoryConfiguration {

    @Primary
    @Bean(name = "adminDataSource")
    @ConfigurationProperties(prefix = "admin.datasource")

    public DataSource adminDataSource() {
        System.out.println("Create datasource Admin");
        return DataSourceBuilder
                .create()
                .build();
    }

    @Primary
    @Bean(name = "adminEntityManager")
    public LocalContainerEntityManagerFactoryBean adminEntityManager(EntityManagerFactoryBuilder builder, @Qualifier("adminDataSource") DataSource adminDataSource) {
        return builder
                .dataSource(adminDataSource)
                .properties(hibernateProperties())
                .packages(User.class, LocalIp.class, CommandLog.class, PipeSize.class, Role.class,Rule.class,Server.class,SshUser.class)
                .persistenceUnit("adminPU")
                .build();
    }

    @Primary
    @Bean(name = "adminTransactionManager")
    public PlatformTransactionManager adminTransactionManager(@Qualifier("adminEntityManager") EntityManagerFactory entityManagerFactory) {
        return new JpaTransactionManager(entityManagerFactory);
    }

    private Map hibernateProperties() {

        Resource resource = new ClassPathResource("hibernate.properties");

        try {
            Properties properties = PropertiesLoaderUtils.loadProperties(resource);

            return properties.entrySet().stream()
                    .collect(Collectors.toMap(
                            e -> e.getKey().toString(),
                            e -> e.getValue())
                    );
        } catch (IOException e) {
            return new HashMap();
        }
    }
}

Repository 1:

@Repository
@Transactional("adminTransactionManager")
public interface SshUserRepository extends JpaRepository<SshUser, Integer> {
    SshUser findByUsername(String username);
}

Repository 2:

@Repository
@Transactional("routerTransactionManager")
public interface SubnetRepository extends JpaRepository<Subnet, Integer> {
    public Subnet findByAddress(Integer address);
    public Subnet findByMask(Integer mask);
}

properties file:

admin.datasource.url= jdbc:mysql://192.168.10.3:3306/pipe?autoReconnect=true&useSSL=false
admin.datasource.username=user
admin.datasource.password=pass
admin.datasource.driverClassName=com.mysql.jdbc.Driver

router.datasource.url= jdbc:mysql://192.168.10.3:3306/router?autoReconnect=true&useSSL=false
router.datasource.username=user
router.datasource.password=pass
router.datasource.driverClassName=com.mysql.jdbc.Driver

hibernate.properties:

#spring.jpa.show-sql = true
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=create-drop

At the start I have this error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field userRepository in net.elyland.pipe.services.UserDetailsServiceImpl required a bean named 'entityManagerFactory' that could not be found.

Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

Here the full log:

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

2017-07-07 18:52:18.774  INFO 11870 --- [           main] n.e.pipe.SpringBootMvcJspApplication     : Starting SpringBootMvcJspApplication on adm-imaterynko with PID 11870 (/home/imaterynko/SVN/sysadm/javawebdev/pipe/target/classes started by imaterynko in /home/imaterynko/SVN/sysadm/javawebdev/pipe)
2017-07-07 18:52:18.780  INFO 11870 --- [           main] n.e.pipe.SpringBootMvcJspApplication     : No active profile set, falling back to default profiles: default
2017-07-07 18:52:18.859  INFO 11870 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6a472554: startup date [Fri Jul 07 18:52:18 EEST 2017]; root of context hierarchy
2017-07-07 18:52:20.485  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'remoteIpRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.487  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'providerRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.488  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'netRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.491  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'queueTypeRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.492  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'ipRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.494  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'subnetRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.497  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'queueRuleRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:20.504  INFO 11870 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'trafficQueueRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-07-07 18:52:21.046  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration' of type [class org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.110  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'validator' of type [class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.158  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [class org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$ee2486b5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.170  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [class org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.172  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@678040b3' of type [class org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.180  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [class org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$12f92967] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.193  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [class org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.203  INFO 11870 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$5576be7b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-07 18:52:21.537  INFO 11870 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-07-07 18:52:21.551  INFO 11870 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-07-07 18:52:21.552  INFO 11870 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.11
2017-07-07 18:52:22.039  INFO 11870 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2017-07-07 18:52:22.042  INFO 11870 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-07-07 18:52:22.042  INFO 11870 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3185 ms
2017-07-07 18:52:22.239  INFO 11870 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-07-07 18:52:22.240  INFO 11870 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2017-07-07 18:52:22.241  INFO 11870 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Filter characterEncodingFilter was not registered (possibly already registered?)
2017-07-07 18:52:22.241  INFO 11870 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
Create datasource Admin
2017-07-07 18:52:22.894  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'adminPU'
2017-07-07 18:52:22.912  INFO 11870 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: adminPU
    ...]
2017-07-07 18:52:22.971  INFO 11870 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.11.Final}
2017-07-07 18:52:22.973  INFO 11870 --- [           main] org.hibernate.cfg.Environment            : HHH000205: Loaded properties from resource hibernate.properties: {hibernate.dialect=org.hibernate.dialect.MySQL5Dialect, hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=create-drop}
2017-07-07 18:52:22.974  INFO 11870 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-07-07 18:52:23.007  INFO 11870 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-07-07 18:52:23.210  INFO 11870 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-07-07 18:52:23.673  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-07-07 18:52:23.685 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table command_log drop foreign key FKo5wo2sqahur6v6uym1t2sjken
2017-07-07 18:52:23.685 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.command_log' doesn't exist
2017-07-07 18:52:23.688 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table host drop foreign key FK9hlhx55t325whiraf8newuxcv
2017-07-07 18:52:23.688 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.host' doesn't exist
2017-07-07 18:52:23.689 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table rule drop foreign key FKeuk4g8c1yhpjno3suq3syen02
2017-07-07 18:52:23.690 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.rule' doesn't exist
2017-07-07 18:52:23.691 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table rule drop foreign key FKtria2gmd5ghsirwucl003p935
2017-07-07 18:52:23.691 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.rule' doesn't exist
2017-07-07 18:52:23.693 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table rule drop foreign key FKsoy6c2wf2ahd7y2awnfabuxkc
2017-07-07 18:52:23.694 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.rule' doesn't exist
2017-07-07 18:52:23.695 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table user drop foreign key FKn82ha3ccdebhokx3a8fgdqeyy
2017-07-07 18:52:23.695 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'pipe.user' doesn't exist
2017-07-07 18:52:24.183  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2017-07-07 18:52:24.238  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'adminPU'
2017-07-07 18:52:24.300  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'routerPU'
2017-07-07 18:52:24.301  INFO 11870 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: routerPU
    ...]
2017-07-07 18:52:24.386  INFO 11870 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-07-07 18:52:24.476  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-07-07 18:52:24.478 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table ip drop foreign key FKnunykfm5kyqpk69fu78rm690t
2017-07-07 18:52:24.478 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.ip' doesn't exist
2017-07-07 18:52:24.479 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table ip drop foreign key FK3fkkinqulfhgjo6c7gu8ptu8f
2017-07-07 18:52:24.479 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.ip' doesn't exist
2017-07-07 18:52:24.481 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table ip drop foreign key FK4txj00furhr0boqimj1s0loa1
2017-07-07 18:52:24.481 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.ip' doesn't exist
2017-07-07 18:52:24.483 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table queue_rule drop foreign key FK5bm4nnopngcrglm6od8m97yhh
2017-07-07 18:52:24.483 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.queue_rule' doesn't exist
2017-07-07 18:52:24.485 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table queue_rule drop foreign key FKohmfk4krumgcaa75kxnfxcwfv
2017-07-07 18:52:24.485 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.queue_rule' doesn't exist
2017-07-07 18:52:24.486 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table queue_rule drop foreign key FKtc36dnb4iulun0yn72wqrybf4
2017-07-07 18:52:24.486 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.queue_rule' doesn't exist
2017-07-07 18:52:24.487 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table queue_rule drop foreign key FK3t8l9ho5h9g7soqrk94h3van0
2017-07-07 18:52:24.487 ERROR 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Table 'router.queue_rule' doesn't exist
2017-07-07 18:52:25.003  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2017-07-07 18:52:25.007  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'routerPU'
2017-07-07 18:52:25.124  WARN 11870 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfiguration': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsServiceImpl': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#693f2213' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#693f2213': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2017-07-07 18:52:25.124  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'routerPU'
2017-07-07 18:52:25.124  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-07-07 18:52:25.523  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2017-07-07 18:52:25.526  INFO 11870 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'adminPU'
2017-07-07 18:52:25.526  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-07-07 18:52:25.920  INFO 11870 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2017-07-07 18:52:25.925  WARN 11870 --- [           main] o.s.boot.SpringApplication               : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available)
2017-07-07 18:52:25.985 ERROR 11870 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

Field userRepository in net.elyland.pipe.services.UserDetailsServiceImpl required a bean named 'entityManagerFactory' that could not be found.

Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

Can somebody say what's wrong?
Thanks.

Body:
When having multiple data sources in spring-boot, use separate class for each data source to for the sake of readability of code as well as to avoid such errors (Consider defining a bean named 'entityManagerFactory' in your configuration.)

In case of single datasource in Application, spring boot would have created a default entityManagerFactory bean for it. But on having multiple data sources we need to define entityManagerFactory & transactionManager explicitly for each of them.

For example, you have to use two data sources in your app ds1 & ds2, create beans like below :

Bean for ds1

@Configuration
@Import(SomePrimaryConfig.class)
@EnableJpaRepositories(
    basePackages = "com.ds1.repos",
    entityManagerFactoryRef = "ds1EMF",
    transactionManagerRef = "ds1TM")
public class DataSource1 {

@Bean
@ConfigurationProperties("ds1.datasource")
public DataSource ds1DataSource() {
    DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
    // other datasource details to set
    return dataSourceBuilder.build();
}

@Bean
LocalContainerEntityManagerFactoryBean ds1EMF(DataSource ds1DataSource) {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(ds1DataSource);
    entityManagerFactoryBean.setPackagesToScan("com.ds1.models");
    //entityManagerFactoryBean.setJpaProperties(jpaProperties);
    return entityManagerFactoryBean;
}

@Bean
JpaTransactionManager ds1TM(EntityManagerFactory ds1EMF) {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(ds1EMF);
    return transactionManager;
 }
}

Bean for ds2

@Configuration
@Import(SomePrimaryConfig.class)
@EnableJpaRepositories(
    basePackages = "com.ds2.repos",
    entityManagerFactoryRef = "ds2EMF",
    transactionManagerRef = "ds2TM")
public class DataSource2 {

@Bean
@ConfigurationProperties("ds2.datasource")
public DataSource ds1DataSource() {
    DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
    // other datasource details to set
    return dataSourceBuilder.build();
}

@Bean
LocalContainerEntityManagerFactoryBean ds2EMF(DataSource ds2DataSource) {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(ds2DataSource);
    entityManagerFactoryBean.setPackagesToScan("com.ds2.models");
    //entityManagerFactoryBean.setJpaProperties(jpaProperties);
    return entityManagerFactoryBean;
}

@Bean
JpaTransactionManager ds2TM(EntityManagerFactory ds2EMF) {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(ds2EMF);
    return transactionManager;
 }
}


来源: stackexchange

问:
How do I know if my serial comms are being closed by GC?
I have a SerialPort object. I have put an event handler on this to monitor disposal, exceptions and received data events:

```<code>mySp.DataReceived += sp_DataReceived;
mySp.ErrorReceived += sp_ErrorReceived;
mySp.Disposed += sp_Disposed;
</code>```

After a few minutes I stop receiving data, but I have good reason to believe this is not an issue with the sender of the serial messages.

I've had issues in this app before with GC disposing things I needed (Threading.Timer objects), so I want to make sure this SerialPort is not being disposed. I attached a Disposed handler, but I've just read GC would not invoke Dispose - so how can I tell if it's GC or an issue elsewhere?

答:
With the GC we can never say if it is or when it is collected - only if it CAN be collected. The rule is "the GC can collect everything that does not have a chain of strong references to a application root." If you got that, the GC will not touch it. If you do not have it the GC may touch it - eventually.

Running the GC is expensive. While it collects, all other threads must pause. Accordingly the Framework is lazy at running it. If it only runs once - on application closure - that is the ideal case. Before that only some rare scenarios can get it into action:

The danger of a OOM Exception. Before those happen, the GC will have collected everything it can.

Manually calling it

various optimsiations. Like trying to collect everything you created inside the function you just finished.

any alternate GC strategy, like the one optimized for servers

As for your problem:

As long as you keep a strong reference to something, it can not be collected.

If you got a strong reference, the GC has to assume you are working on it and it is not supposed to remove it. It may still do other background stuff with it (like moving it around in memory), but those changes are usually invisible for you.

The only way to cause a memory leak with a GC like this, is to forgetting to remove all strong references to something. Mostly it is people forgetting to remove it from a Collection.

Event handlers by design do not count as "a unbroken chain of strong references". GUI Automatics already have a strong reference chain to everything that is displayed (and the stuff that is only hidden, not undisplayed).

I think you are doing some wierd way of multitasking like this:

you create a instance

you register events

you do not keep a strong reference

This will not work. You need to use a proper way of multitasking - ideally using some blocking or polling code - to process them. That would also allow you to get Exceptions out of the SerialPorts.

ContentLicense: CC BY-SA 4.0

Body:
I have a SerialPort object. I have put an event handler on this to monitor disposal, exceptions and received data events:

mySp.DataReceived += sp_DataReceived;
mySp.ErrorReceived += sp_ErrorReceived;
mySp.Disposed += sp_Disposed;

After a few minutes I stop receiving data, but I have good reason to believe this is not an issue with the sender of the serial messages.

I've had issues in this app before with GC disposing things I needed (Threading.Timer objects), so I want to make sure this SerialPort is not being disposed. I attached a Disposed handler, but I've just read GC would not invoke Dispose - so how can I tell if it's GC or an issue elsewhere?


问:
What is the difference between these two C++ statements to concatenate a string?
I'm new to C++ and I was wondering what the difference is between these two lines:

```<code>cout << "John " << "Doe" << endl;
cout << "John " + "Doe" << endl;
</code>```

The first one works but the second one doesn't. Any ideas?

答:
First one inserts "John " into the standard output, and then it inserts "Doe". End result is that you see both strings in a sequence.

The second attempts to use the addition operator with arrays as operands. This is ill-formed because such operator does not exist in C++.

Body:
I'm new to C++ and I was wondering what the difference is between these two lines:

cout << "John " << "Doe" << endl;
cout << "John " + "Doe" << endl;

The first one works but the second one doesn't. Any ideas?


问:
How to create a update patch link Joomla update from SVN
I saw that in Joomla every time they release a new update. it only contain the file that have been change from the last release with the same directory structure.
So I have a SVN server. And I have modified something in the SVN and now I want to create the update path like Joomla how can I do that?

Thanks, for Your Answer!!!

答:
Using TortoiseSVN in Windows you can follow these steps (copy&pasted from this source):

Using TortoiseSVN, right-click on your working folder and select “Show Log” from the TortoiseSVN menu.

Click the revision that was last published (#85 in this example)

Ctrl+Click the HEAD revision (or whatever revision you want to release ie #178) so that both the old and the new revisions are highlighted.

Right-click on either of the highlighted revisions and select “Compare revisions.”  This will open a dialog window that lists all new/modified files.

Select all files from this list (Ctrl+a) then right-click on the highlighted files and select “Export selection to…”

For use in Linux I have found a script creating the whole directory structure based on the output of this line:

```<code>svn diff -r <revision_number>:HEAD --summarize <working_directory>
</code>```

The script can be found here.

ContentLicense: CC BY-SA 2.5

Body:
Using TortoiseSVN in Windows you can follow these steps (copy&pasted from this source):

Using TortoiseSVN, right-click on your working folder and select “Show Log” from the TortoiseSVN menu.

Click the revision that was last published (#85 in this example)

Ctrl+Click the HEAD revision (or whatever revision you want to release ie #178) so that both the old and the new revisions are highlighted.

Right-click on either of the highlighted revisions and select “Compare revisions.”  This will open a dialog window that lists all new/modified files.

Select all files from this list (Ctrl+a) then right-click on the highlighted files and select “Export selection to…”

For use in Linux I have found a script creating the whole directory structure based on the output of this line:

svn diff -r <revision_number>:HEAD --summarize <working_directory>

The script can be found here.

ContentLicense: CC BY-SA 3.0


问:
How to change http.sys web server response when maxconnection limit reached
We are using http sys web server to host web api service. Business requires to limit maximum number of concurrent connections. MaxConnections configuration property used for that purpose:

```<code>services.Configure<HttpSysOptions>(options =>
{
    options.MaxConnections = Configuration.GetValue<long?>("MaxConnections");
});
</code>```

But in case when concurrent connection limit reached all new connections got dropped on a socket level. Is it possible to change this behaviour so server accepts the request and returns 4xx or 5xx response to the client?

答:
I have finally managed to find a solution: there is Http503Verbosity property in options. By default it is set to Http503VerbosityLevel.Basic but if to change it to Http503VerbosityLevel .Limited or Http503VerbosityLevel.Full 503 response will be returned for requests above limit. So my code looks like this now:</p>

```<code>        services.Configure<HttpSysOptions>(options =>
        {
            options.MaxConnections = Configuration.GetValue<long?>("MaxConnections");
            options.Http503Verbosity = Http503VerbosityLevel.Full;
        });
</code>```

Body:
We are using http sys web server to host web api service. Business requires to limit maximum number of concurrent connections. MaxConnections configuration property used for that purpose:

services.Configure<HttpSysOptions>(options =>
{
    options.MaxConnections = Configuration.GetValue<long?>("MaxConnections");
});

But in case when concurrent connection limit reached all new connections got dropped on a socket level. Is it possible to change this behaviour so server accepts the request and returns 4xx or 5xx response to the client?

Body:
I have finally managed to find a solution: there is Http503Verbosity property in options. By default it is set to Http503VerbosityLevel.Basic but if to change it to Http503VerbosityLevel .Limited or Http503VerbosityLevel.Full 503 response will be returned for requests above limit. So my code looks like this now:

        services.Configure<HttpSysOptions>(options =>
        {
            options.MaxConnections = Configuration.GetValue<long?>("MaxConnections");
            options.Http503Verbosity = Http503VerbosityLevel.Full;
        });


问:
Not splitting a string properly in scala
I have a string:

```<code>var string = "PRODUCTIDENTIFIER|UTLEVEL10|UTLEVEL10DESCRIPTION|UTLEVEL15|UTLEVEL15DESCRIPTION|UTLEVEL17|UTLEVEL17DESCRIPTION|UTLEVEL20|UTLEVEL20DESCRIPTION|UTLEVEL30|UTLEVEL30DESCRIPTION|ACCT_YR|UTCODE"
</code>```

When I try to do string.split("|"), it ends up giving me all the letters of all words in an array like:

```<code>scala> string.split("|")
res0: Array[String] = Array(|, P, R, O, D, U, C, T, I, D, E, N, T, I, F, I, E, R, |, U, T, L, E, V, E, L, 1, 0, |, U, T, L, E, V, E, L, 1, 0, D, E, S, C, R, I, P, T, I, O, N, |, U, T, L, E, V, E, L, 1, 5, |, U, T, L, E, V, E, L, 1, 5, D, E, S, C, R, I, P, T, I, O, N, |, U, T, L, E, V, E, L, 1, 7, |, U, T, L, E, V, E, L, 1, 7, D, E, S, C, R, I, P, T, I, O, N, |, U, T, L, E, V, E, L, 2, 0, |, U, T, L, E, V, E, L, 2, 0, D, E, S, C, R, I, P, T, I, O, N, |, U, T, L, E, V, E, L, 3, 0, |, U, T, L, E, V, E, L, 3, 0, D, E, S, C, R, I, P, T, I, O, N, |, A, C, C, T, _, Y, R, |, U, T, C, O, D, E)
</code>```

What I actually expected was the string will be split based on the | mark. Any idea as to why this does not work?

答:
| is a regex special character.

Try string.split("\\|")

Body:
I have a string:

var string = "PRODUCTIDENTIFIER|UTLEVEL10|UTLEVEL10DESCRIPTION|UTLEVEL15|UTLEVEL15DESCRIPTION|UTLEVEL17|UTLEVEL17DESCRIPTION|UTLEVEL20|UTLEVEL20DESCRIPTION|UTLEVEL30|UTLEVEL30DESCRIPTION|ACCT_YR|UTCODE"

When I try to do string.split("|"), it ends up giving me all the letters of all words in an array like:

scala> string.split("|")
res0: Array[String] = Array(|, P, R, O, D, U, C, T, I, D, E, N, T, I, F, I, E, R, |, U, T, L, E, V, E, L, 1, 0, |, U, T, L, E, V, E, L, 1, 0, D, E, S, C, R, I, P, T, I, O, N, |, U, T, L, E, V, E, L, 1, 5, |, U, T, L, E, V, E, L, 1, 5, D, E, S, C, R, I, P, T, I, O, N, |, U, T, L, E, V, E, L, 1, 7, |, U, T, L, E, V, E, L, 1, 7, D, E, S, C, R, I, P, T, I, O, N, |, U, T, L, E, V, E, L, 2, 0, |, U, T, L, E, V, E, L, 2, 0, D, E, S, C, R, I, P, T, I, O, N, |, U, T, L, E, V, E, L, 3, 0, |, U, T, L, E, V, E, L, 3, 0, D, E, S, C, R, I, P, T, I, O, N, |, A, C, C, T, _, Y, R, |, U, T, C, O, D, E)

What I actually expected was the string will be split based on the | mark. Any idea as to why this does not work?


问:
List of custom ports for EMR master and slave node
I am working on a data project, I am using EMR cluster for data processing
My AWS environment is restricted it doesn't allow me to use EMR manage security group
For that, I need a list of custom ports for EMR master and slave node. </p>

答:
You can see list of Web Interfaces Hosted on Amazon EMR Clusters.

To see what other ports listening on any node

netstat -tunalp | grep LISTEN
```


问:
Eclipse doesn't see JavaFX properties in css file, "unknown property"
I installed Eclipse and downloaded the OpenJFX SDK. But the problem is that Eclipse marks all -fx- properties in the .css file as warning and writes "unknown property". My JavaFX projects compile and run fine - I followed the instructions on the official JavaFX website. But CSS auto-completion has no properties. In addition, when I add the JavaFX SDK Library to the Build Path, it does not appear in Project Explorer, maybe this is due. Also I have installed e(fx)clipse.

答:
Solution:
Delete e(fx)clipse plugin; try to install again from

http://download.eclipse.org/efxclipse/updates-released/3.6.0/site

https://download.eclipse.org/efxclipse/updates-nightly/site

, probably you will be noticed that due unsatisfied dependencies version will be automatically downgraded (3.6.0 -> 3.5.7 in my case). If so, install m2e support from same repository:


问:
React Native Responsive Font Size
I would like to ask how react native handle or do the responsive font. For example in iphone 4s i Have fontSize: 14, while in iphone 6 I have fontSize: 18.</p>

答:
Need to use this way I have used this one and it's working fine.

react-native-responsive-screen
npm install react-native-responsive-screen --save

Just like I have a device 1080x1920

```<code>The vertical number we calculate from height **hp**
height:200
200/1920*100 = 10.41% - height:hp("10.41%")

The Horizontal number we calculate from width **wp**
width:200
200/1080*100 = 18.51% - Width:wp("18.51%")
</code>```

It's working for all device

Title: React Native Responsive Font Size

Body:
Need to use this way I have used this one and it's working fine.

react-native-responsive-screen
npm install react-native-responsive-screen --save

Just like I have a device 1080x1920

The vertical number we calculate from height **hp**
height:200
200/1920*100 = 10.41% - height:hp("10.41%")

The Horizontal number we calculate from width **wp**
width:200
200/1080*100 = 18.51% - Width:wp("18.51%")

It's working for all device


问:
How to change event dbl-click in code-mirror
I want to change the event dbl click but my code is not correct and does not work
What I want the code to do

my code

my jquery code for code-mirror

```<code>function Script() {
  var ua = navigator.userAgent;
  if (ua && ua.toUpperCase().indexOf("OPERA MINI") > -1) {
  return false;
  }
  window.editor = CodeMirror.fromTextArea(document.getElementById("fldScript"), {
  mode: "text/javascript",
  htmlMode: true,
  lineWrapping: true,
  autoCloseTags: true,
  smartIndent: false,
  addModeClass: true,
  extraKeys: {
     "Ctrl-Space": "autocomplete",
     /*-------------- function dbl-click------------------*/
     "dblclick" : function(cm) {
       cm.setOption("fullScreen", !cm.getOption("fullScreen"));
     },
     /*-------------- function key-press F11------------------*/
     "F11": function(cm) {
       cm.setOption("fullScreen", !cm.getOption("fullScreen"));
     },
     "Esc": function(cm) {
     if (cm.getOption("fullScreen"))
        cm.setOption("fullScreen", false);
     }
    }
  });
  window.editor.on("change", function() {
    window.editor.save();
  });
}
Script();
</code>```

答:
```<code>function Script() {
  var ua = navigator.userAgent;
  if (ua && ua.toUpperCase().indexOf("OPERA MINI") > -1) {
return false;
}
  window.editor = CodeMirror.fromTextArea(document.getElementById("fldScript"), {
mode: "javascript",
htmlMode: true,
lineWrapping: true,
autoCloseTags: true,
smartIndent: false,
addModeClass: true,
extraKeys: {
  "Ctrl-Space": "autocomplete",
  "F11": function(cm) {
    cm.setOption("fullScreen", !cm.getOption("fullScreen"));
  },
  "Esc": function(cm) {
    if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
  }
}
  });
  window.editor.on("change", function() {
   window.editor.save();
 });
  window.editor.on('dblclick', function() {
   if (window.editor.getOption("fullScreen") == false)
window.editor.setOption("fullScreen", !window.editor.getOption("fullScreen"));
  });
}
Script();
</code>```

Body:
I want to change the event dbl click but my code is not correct and does not work
What I want the code to do

my code

my jquery code for code-mirror

function Script() {
  var ua = navigator.userAgent;
  if (ua && ua.toUpperCase().indexOf("OPERA MINI") > -1) {
  return false;
  }
  window.editor = CodeMirror.fromTextArea(document.getElementById("fldScript"), {
  mode: "text/javascript",
  htmlMode: true,
  lineWrapping: true,
  autoCloseTags: true,
  smartIndent: false,
  addModeClass: true,
  extraKeys: {
     "Ctrl-Space": "autocomplete",
     /*-------------- function dbl-click------------------*/
     "dblclick" : function(cm) {
       cm.setOption("fullScreen", !cm.getOption("fullScreen"));
     },
     /*-------------- function key-press F11------------------*/
     "F11": function(cm) {
       cm.setOption("fullScreen", !cm.getOption("fullScreen"));
     },
     "Esc": function(cm) {
     if (cm.getOption("fullScreen"))
        cm.setOption("fullScreen", false);
     }
    }
  });
  window.editor.on("change", function() {
    window.editor.save();
  });
}
Script();


问:
Javascript : Create a variable that returns me only the first word of page title
I have a website page with a three words title.
how can I create a variable in Javascript that outputs only the first word of that title ?

thanks for your help !

答:
There are a lot of way to do that. If you have these words separated by space, the simplest and straightforward you can write the following:

```<code>const firstWord = pageTitle.split(' ')[0];
</code>```

If you need to extract page title from browser API, just address document.title and use it as pageTitle variable.

Body:
There are a lot of way to do that. If you have these words separated by space, the simplest and straightforward you can write the following:

const firstWord = pageTitle.split(' ')[0];

If you need to extract page title from browser API, just address document.title and use it as pageTitle variable.


问:
Regex Capture one word OR two words in quotes
I'm trying to implement gmail style filters in my search and I'm stuck at this regex problem. I need to capture ONE word OR two words in quotes (but without the quotation marks themselves) This is PCRE (PHP)

ie.

```<code>name:mark
</code>```

desired result: 1st capture group should be mark

```<code>name:"mark"
</code>```

desired result: 1st capture group should be mark

```<code>name:"mark wilson"
</code>```

desired result: 1st capture group should be mark, second capture group should be wilson

```<code>name:mark wilson
</code>```

desired result: 1st capture group should be mark, wilson is ignored

The closest I've gotten is name:(\w+|\"\w+(?>\"|\s([a-z.'-]+\"))) it captures example 1 perfectly, but example 2 still includes the quotes, and example 3 ends up as:

group 1: "mark wilson"  (quotes included)

group 2: wilson"        (quote included)

I've tried lookahead and lookbehinds but I'm not getting anywhere with those either

any help would be very appreciated. tia

答:
1 option could be using an if/else clause which will give mark in group 2 and wilson in group 3. The first group will capture the " which can be used for the if else checking for the existence for group 1.

```<code>\w+:(")?(\w+(?:\h+(\w+))?)(?(1)")
</code>```

Regex demo

If the space after the first name should not be there, you could also group that and have the values in group 3 and 4

```<code>\w+:(")?((\w+)(?:\h+(\w+))?)(?(1)")
</code>```

Regex demo

You could also get either the single value between quotes or not, or capture the first or second name in a capturing group using a branch reset group

```<code>\w+:(?|"(\w+)(?:\h+(\w+))?"|(\w+))
</code>```

Explanation

\w+: Match 1+ word chars

(?| Branch reset group

"(\w+) Capture group 1, match 1+ word chars

(?: Non capture group

\h+ match 1+ horizontal whitespace chars

(\w+) Capture group 2, match 1+ word chars

)? Close group and make optional

" Match "

| Or

(\w+) Capture group 1, match 1+ word chars

) Close branch reset group

Regex demo

Body:
I'm trying to implement gmail style filters in my search and I'm stuck at this regex problem. I need to capture ONE word OR two words in quotes (but without the quotation marks themselves) This is PCRE (PHP)

ie.

name:mark

desired result: 1st capture group should be mark

name:"mark"

desired result: 1st capture group should be mark

name:"mark wilson"

desired result: 1st capture group should be mark, second capture group should be wilson

name:mark wilson

desired result: 1st capture group should be mark, wilson is ignored

The closest I've gotten is name:(\w+|\"\w+(?>\"|\s([a-z.'-]+\"))) it captures example 1 perfectly, but example 2 still includes the quotes, and example 3 ends up as:

group 1: "mark wilson"  (quotes included)

group 2: wilson"        (quote included)

I've tried lookahead and lookbehinds but I'm not getting anywhere with those either

any help would be very appreciated. tia

Body:
1 option could be using an if/else clause which will give mark in group 2 and wilson in group 3. The first group will capture the " which can be used for the if else checking for the existence for group 1.

\w+:(")?(\w+(?:\h+(\w+))?)(?(1)")

Regex demo

If the space after the first name should not be there, you could also group that and have the values in group 3 and 4

\w+:(")?((\w+)(?:\h+(\w+))?)(?(1)")

Regex demo

You could also get either the single value between quotes or not, or capture the first or second name in a capturing group using a branch reset group

\w+:(?|"(\w+)(?:\h+(\w+))?"|(\w+))

Explanation

\w+: Match 1+ word chars

(?| Branch reset group

"(\w+) Capture group 1, match 1+ word chars

(?: Non capture group

\h+ match 1+ horizontal whitespace chars

(\w+) Capture group 2, match 1+ word chars

)? Close group and make optional

" Match "

| Or

(\w+) Capture group 1, match 1+ word chars

) Close branch reset group

Regex demo


问:
Nested array computations in Python using numpy
I am trying to use numpy in Python in solving my project.

I have a random binary array  rndm = [1, 0, 1, 1] and a resource_arr = [[2, 3], 4, 2, [1, 2]]. What I am trying to do is to multiply the array element wise, then get their sum. As an expected output for the sample above,
output = 5 0 2 3. I find hard to solve such problem because of the nested array/list.

So far my code looks like this:

```<code>   def fitness_score():

   output = numpy.add(rndm * resource_arr)
   return output

   fitness_score()
</code>```

I keep getting

```<code>ValueError: invalid number of arguments.
</code>```

For which I think is because of the addition that I am trying to do. Any help would be appreciated. Thank you!

答:
Numpy is all about the non-jagged arrays. You can do things with jagged arrays, but doing so efficiently and elegantly isnt trivial.

Almost always, trying to find a way to map your datastructure to a non-nested one, for instance, encoding the information as below, will be more flexible, and more performant.

```<code>resource_arr = (
    [0, 0, 1, 2, 3, 3]
    [2, 3, 4, 2, 1, 2]
)
</code>```

That is, an integer denoting the 'row' each value belongs to, paired with an array of equal size of the values themselves.

This may 'feel' wasteful when coming from a C-style way of doing arrays (omg more memory consumption), but staying away from nested datastructures is almost certainly your best bet in terms of performance, and the amount of numpy/scipy ecosystem that will actually be compatible with your data representation. If it really uses more memory is actually rather questionable; every new python object uses a ton of bytes, so if you have only few elements per nesting, it is the more memory efficient solution too.

In this case, that would give you the following efficient solution to your problem:

```<code>output = np.bincount(*resource_arr) * rndm
</code>```

Body:
I am trying to use numpy in Python in solving my project.

I have a random binary array  rndm = [1, 0, 1, 1] and a resource_arr = [[2, 3], 4, 2, [1, 2]]. What I am trying to do is to multiply the array element wise, then get their sum. As an expected output for the sample above,
output = 5 0 2 3. I find hard to solve such problem because of the nested array/list.

So far my code looks like this:

   def fitness_score():

   output = numpy.add(rndm * resource_arr)
   return output

   fitness_score()

I keep getting

ValueError: invalid number of arguments.

For which I think is because of the addition that I am trying to do. Any help would be appreciated. Thank you!

Body:
Numpy is all about the non-jagged arrays. You can do things with jagged arrays, but doing so efficiently and elegantly isnt trivial.

Almost always, trying to find a way to map your datastructure to a non-nested one, for instance, encoding the information as below, will be more flexible, and more performant.

resource_arr = (
    [0, 0, 1, 2, 3, 3]
    [2, 3, 4, 2, 1, 2]
)

That is, an integer denoting the 'row' each value belongs to, paired with an array of equal size of the values themselves.

This may 'feel' wasteful when coming from a C-style way of doing arrays (omg more memory consumption), but staying away from nested datastructures is almost certainly your best bet in terms of performance, and the amount of numpy/scipy ecosystem that will actually be compatible with your data representation. If it really uses more memory is actually rather questionable; every new python object uses a ton of bytes, so if you have only few elements per nesting, it is the more memory efficient solution too.

In this case, that would give you the following efficient solution to your problem:

output = np.bincount(*resource_arr) * rndm


问:
Android Streaming Video using MediaPlayer
I'm back with another problem!

I'm trying to create an app that would list a selected Livestreams, from Own3d.TV, Justin.Tv etc...

If my research isn't totally failed, I can use the MediaPlayer object to Stream video, the only question is how do I use it?

So far my code looks like this, but it's giving me an Exception when trying to prepare the MediaPlayer.

```<code>public class Media extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    SurfaceView sw = new SurfaceView(this);
    SurfaceHolder sh = sw.getHolder();

    setContentView(sw);

    Uri ur = Uri.parse("http://www.twitch.tv/widgets/live_embed_player.swf?channel=hashe");

    MediaPlayer mp = new MediaPlayer();

    mp.setDisplay(sh);

    try {
        mp.setDataSource("http://www.twitch.tv/widgets/live_embed_player.swf?channel=hashe");
        mp.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    mp.start();
    //mp.setDisplay(sw);

}
}
</code>```

Is it even possible to Stream the video from these sites using the MediaPlayer?

If not, how shoud I approach this problem?

Thanks!

答:
Use ExoPlayer instead of MediaPlayer. See Android official documentation:

ExoPlayer supports features like Dynamic adaptive streaming over HTTP (DASH), SmoothStreaming and Common Encryption, which are not supported by MediaPlayer. It's designed to be easy to customize and extend.

ExoPlayer - Android Developers

Body:
I'm back with another problem!

I'm trying to create an app that would list a selected Livestreams, from Own3d.TV, Justin.Tv etc...

If my research isn't totally failed, I can use the MediaPlayer object to Stream video, the only question is how do I use it?

So far my code looks like this, but it's giving me an Exception when trying to prepare the MediaPlayer.

public class Media extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    SurfaceView sw = new SurfaceView(this);
    SurfaceHolder sh = sw.getHolder();

    setContentView(sw);

    Uri ur = Uri.parse("http://www.twitch.tv/widgets/live_embed_player.swf?channel=hashe");

    MediaPlayer mp = new MediaPlayer();

    mp.setDisplay(sh);

    try {
        mp.setDataSource("http://www.twitch.tv/widgets/live_embed_player.swf?channel=hashe");
        mp.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    mp.start();
    //mp.setDisplay(sw);

}
}

Is it even possible to Stream the video from these sites using the MediaPlayer?

If not, how shoud I approach this problem?

Thanks!


问:
Cannot add server to Visual Studio Server Explorer
I am unable to add a remote server to the Visual Studio Server Explorer for my ASP.Net website which has been running for about 9 months.

I have added a connection to the database that is working well.

The error message leads me to think I may not have the path entered correctly. I have tried a number of combinations, including using the IP Address.

Error Message:
Could not reconnect to "servername".
Make sure that the machine name and path are valid.

答: If the server is a remote server then may be the firewall is blocking. Check firewall in the machine in which SQL server is running.</p>

OwnerDisplayName: hunterpaw

LastEditorDisplayName: hunterpaw


问:
Updating Chartjs dataset in Ionic
I was trying to update a bar chart dataset by appending newer data to it using Chartjs. According to doc here, I need to update the datasets.data array and labels. I created the following component in Ionic:

chart.component.ts

```<code>import { SensorDataService } from './sensor-data.service';
import { Component, Input, AfterViewInit, ViewChild, ElementRef } from '@angular/core';

declare var Chart: any;

@Component({
  selector: 'app-chart',
  templateUrl: './chart.component.html',
  styleUrls: ['./chart.component.scss'],
})
export class ChartComponent implements AfterViewInit {
  //@Input() chartId: string;
  //@Input() chartTitle: string;
  @Input() data: Array<number>;
  @Input() labels: Array<string>;
  //@Input() datasetLabel: string;
  interval: any;
  count: number;
  @ViewChild('chart') chartRef: ElementRef;
  chart: any;

  constructor(private dataService: SensorDataService) { }

  ngAfterViewInit() {
    console.log(this.data);
    console.log(this.labels);
    this.chart = new Chart(this.chartRef.nativeElement, {
      type: 'bar',
      data: {
        labels: this.labels,
        datasets: [{
          label: 'label',
          data: this.data,
          backgroundColor: 'rgb(0, 0, 255)',
          borderWidth: 1
        }]
      },
      options: {
        scales: {
          yAxes: [
            {
              ticks: {
                beginAtZero: true
              }
            }
          ]
        }
      }
    });
    this.count = 0;
    this.interval = setInterval(this.loadData.bind(this), 5000);
  }
  loadData() {
    if (this.count > 10) {
      return clearInterval(this.interval);
    }
    const { data, labels } = this.dataService.getData();
    console.log('data loaded');
    console.log(this.chart.data.labels);
    console.log(this.chart.data.datasets[0].data);
    this.chart.data.labels.concat(labels);
    this.chart.data.datasets.forEach(ds => ds.data.concat(data));
    this.count++;
    this.chart.update();
  }
}
</code>```

chart.component.html

```<code><ion-card>
    <ion-card-header>
        <ion-card-title>Title</ion-card-title>
    </ion-card-header>
    <ion-card-content>
        <canvas #chart></canvas>
    </ion-card-content>
</ion-card>
</code>```

From the console log, I don't see any changes in the size of the array. The graph remains the same as well. I created this as a test before connecting the data from http endpoint where, each request will return newer data and I have to append it to the existing chart. What's wrong with my code as given here and why is the chart not updating?

答:
The Array.concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

Therefore, you should change your loadData() method as follows:

```<code>loadData() {
  if (this.count > 10) {
    return clearInterval(this.interval);
  }
  const { data, labels } = this.dataService.getData();
  this.chart.data.labels = this.chart.data.labels.concat(labels);
  this.chart.data.datasets.forEach(ds => ds.data = ds.data.concat(data));
  this.count++;
  this.chart.update();
}
</code>```

Title: Updating Chartjs dataset in Ionic

Body:
I was trying to update a bar chart dataset by appending newer data to it using Chartjs. According to doc here, I need to update the datasets.data array and labels. I created the following component in Ionic:

chart.component.ts

import { SensorDataService } from './sensor-data.service';
import { Component, Input, AfterViewInit, ViewChild, ElementRef } from '@angular/core';

declare var Chart: any;

@Component({
  selector: 'app-chart',
  templateUrl: './chart.component.html',
  styleUrls: ['./chart.component.scss'],
})
export class ChartComponent implements AfterViewInit {
  //@Input() chartId: string;
  //@Input() chartTitle: string;
  @Input() data: Array<number>;
  @Input() labels: Array<string>;
  //@Input() datasetLabel: string;
  interval: any;
  count: number;
  @ViewChild('chart') chartRef: ElementRef;
  chart: any;

  constructor(private dataService: SensorDataService) { }

  ngAfterViewInit() {
    console.log(this.data);
    console.log(this.labels);
    this.chart = new Chart(this.chartRef.nativeElement, {
      type: 'bar',
      data: {
        labels: this.labels,
        datasets: [{
          label: 'label',
          data: this.data,
          backgroundColor: 'rgb(0, 0, 255)',
          borderWidth: 1
        }]
      },
      options: {
        scales: {
          yAxes: [
            {
              ticks: {
                beginAtZero: true
              }
            }
          ]
        }
      }
    });
    this.count = 0;
    this.interval = setInterval(this.loadData.bind(this), 5000);
  }
  loadData() {
    if (this.count > 10) {
      return clearInterval(this.interval);
    }
    const { data, labels } = this.dataService.getData();
    console.log('data loaded');
    console.log(this.chart.data.labels);
    console.log(this.chart.data.datasets[0].data);
    this.chart.data.labels.concat(labels);
    this.chart.data.datasets.forEach(ds => ds.data.concat(data));
    this.count++;
    this.chart.update();
  }
}

chart.component.html

<ion-card>
    <ion-card-header>
        <ion-card-title>Title</ion-card-title>
    </ion-card-header>
    <ion-card-content>
        <canvas #chart></canvas>
    </ion-card-content>
</ion-card>

From the console log, I don't see any changes in the size of the array. The graph remains the same as well. I created this as a test before connecting the data from http endpoint where, each request will return newer data and I have to append it to the existing chart. What's wrong with my code as given here and why is the chart not updating?

Body:
The Array.concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

Therefore, you should change your loadData() method as follows:

loadData() {
  if (this.count > 10) {
    return clearInterval(this.interval);
  }
  const { data, labels } = this.dataService.getData();
  this.chart.data.labels = this.chart.data.labels.concat(labels);
  this.chart.data.datasets.forEach(ds => ds.data = ds.data.concat(data));
  this.count++;
  this.chart.update();
}