问:
spring + hibernate configuration error ? XML document from class path resource [spring.xml] is invalid
i am currently trying to configure spring with hibernate in a maven project (webapp). However, I have an error that I have not been able to resolve for 2 weeks.

pom.xml :

```<code> <?xml version="1.0" encoding="UTF-8"?>

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.oc</groupId>
  <artifactId>nom</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>nom Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <spring.version>5.2.1.RELEASE</spring.version>
    <hibernate.version>5.4.10.Final</hibernate.version>
    <!-- Logging -->
    <logback.version>1.0.13</logback.version>
    <slf4j.version>1.7.5</slf4j.version>
  </properties>

  <dependencies>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
    </dependency>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>${hibernate.version}</version>
    </dependency>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>${hibernate.version}</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-framework-bom</artifactId>
      <version>${spring.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>5.2.2.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.17</version>
    </dependency>

    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.4</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>${logback.version}</version>
      <scope>runtime</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>nom</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
</code>```

spring.xml :

```<code><beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://springframework.org/schema/beans/spring-beans-5.2.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/db_person" />
        <property name="username" value="root" />
        <property name="password" value="0324" />
    </bean>

    <!-- Hibernate 5 XML SessionFactory Bean definition-->
        <bean id="hibernate5SessionFactory"
            class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="mappingResources">
                <list>
                    <value>person.hbm.xml</value>
                </list>
            </property>
            <property name="hibernateProperties">
                <value>
                    hibernate.dialect=org.hibernate.dialect.MySQLDialect
                </value>
            </property>
        </bean>

    <!-- Hibernate 5 Annotation SessionFactory Bean definition-->
    <bean id="hibernate5AnnotatedSessionFactory"
          class="org.springframework.orm.hibernate5.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.oc.model.Person</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.current_session_context_class">thread</prop>
                <prop key="hibernate.show_sql">false</prop>
            </props>
        </property>
    </bean>

    <bean id="personDAO" class="com.oc.dao.PersonDAOImpl">
        <property name="sessionFactory" ref="hibernate5AnnotatedSessionFactory" />
    </bean>
</beans>
</code>```

person.hbm.xml :

```<code><?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name = "com.oc.model.Person" table = "person">

        <meta attribute = "class-description">
            This class contains the employee detail.
        </meta>

        <id name = "id" type = "int" column = "id">
            <generator class="native"/>
        </id>

        <property name = "name" column = "name" type = "string"/>
        <property name = "country" column = "country" type = "string"/>

    </class>
</hibernate-mapping>
</code>```

Person.java :

```<code>package com.oc.model;

import javax.persistence.*;

@Entity
@Table(name ="Person")
public class Person {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    private String name;

    private String country;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    @Override
    public String toString(){
        return "id="+id+", name="+name+", country="+country;
    }
}
</code>```

Main.java :

```<code>package com.oc.main;

import com.oc.dao.PersonDAO;
import com.oc.model.Person;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class Main {
        public static void main(String[] args) {

            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

            PersonDAO personDAO = context.getBean(PersonDAO.class);

            Person person = new Person();
            person.setName("geo"); person.setCountry("france");

            personDAO.save(person);

            System.out.println("Person::"+person);

            List<Person> list = personDAO.list();

            for(Person p : list){
                System.out.println("Person List::"+p);
            }
            //close resources
            context.close();
        }

}
</code>```

the project organization

When compiling the main.java, I get the following error:

```<code>Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 5 in XML document from class path resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 68; cvc-elt.1.a : Déclaration de l'élément 'beans' introuvable.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:405)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:337)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:305)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:637)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:522)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
    at com.oc.main.Main.main(Main.java:12)
Caused by: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 68; cvc-elt.1.a : Déclaration de l'élément 'beans' introuvable.
    at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
    at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:135)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
    at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2132)
    at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:829)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:613)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3063)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:836)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)
    at java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:77)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:435)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:393)
    ... 14 more
</code>```

Can you help me solve my problem?

答:
http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

With your article, i change  xsi:schemaLocation and it's ok. thx

Body:
i am currently trying to configure spring with hibernate in a maven project (webapp). However, I have an error that I have not been able to resolve for 2 weeks.

pom.xml :

 <?xml version="1.0" encoding="UTF-8"?>

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.oc</groupId>
  <artifactId>nom</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>nom Maven Webapp</name>

  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <spring.version>5.2.1.RELEASE</spring.version>
    <hibernate.version>5.4.10.Final</hibernate.version>

    <logback.version>1.0.13</logback.version>
    <slf4j.version>1.7.5</slf4j.version>
  </properties>

  <dependencies>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
    </dependency>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>${hibernate.version}</version>
    </dependency>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>${hibernate.version}</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-framework-bom</artifactId>
      <version>${spring.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>5.2.2.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.17</version>
    </dependency>

    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.4</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>${logback.version}</version>
      <scope>runtime</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>nom</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>

        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

spring.xml :

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://springframework.org/schema/beans/spring-beans-5.2.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/db_person" />
        <property name="username" value="root" />
        <property name="password" value="0324" />
    </bean>

        <bean id="hibernate5SessionFactory"
            class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="mappingResources">
                <list>
                    <value>person.hbm.xml</value>
                </list>
            </property>
            <property name="hibernateProperties">
                <value>
                    hibernate.dialect=org.hibernate.dialect.MySQLDialect
                </value>
            </property>
        </bean>

    <bean id="hibernate5AnnotatedSessionFactory"
          class="org.springframework.orm.hibernate5.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.oc.model.Person</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.current_session_context_class">thread</prop>
                <prop key="hibernate.show_sql">false</prop>
            </props>
        </property>
    </bean>

    <bean id="personDAO" class="com.oc.dao.PersonDAOImpl">
        <property name="sessionFactory" ref="hibernate5AnnotatedSessionFactory" />
    </bean>
</beans>

person.hbm.xml :

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name = "com.oc.model.Person" table = "person">

        <meta attribute = "class-description">
            This class contains the employee detail.
        </meta>

        <id name = "id" type = "int" column = "id">
            <generator class="native"/>
        </id>

        <property name = "name" column = "name" type = "string"/>
        <property name = "country" column = "country" type = "string"/>

    </class>
</hibernate-mapping>

Person.java :

package com.oc.model;

import javax.persistence.*;

@Entity
@Table(name ="Person")
public class Person {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    private String name;

    private String country;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    @Override
    public String toString(){
        return "id="+id+", name="+name+", country="+country;
    }
}

Main.java :

package com.oc.main;

import com.oc.dao.PersonDAO;
import com.oc.model.Person;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class Main {
        public static void main(String[] args) {

            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

            PersonDAO personDAO = context.getBean(PersonDAO.class);

            Person person = new Person();
            person.setName("geo"); person.setCountry("france");

            personDAO.save(person);

            System.out.println("Person::"+person);

            List<Person> list = personDAO.list();

            for(Person p : list){
                System.out.println("Person List::"+p);
            }
            //close resources
            context.close();
        }

}

the project organization

When compiling the main.java, I get the following error:

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 5 in XML document from class path resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 68; cvc-elt.1.a : Déclaration de l'élément 'beans' introuvable.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:405)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:337)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:305)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:637)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:522)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
    at com.oc.main.Main.main(Main.java:12)
Caused by: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 68; cvc-elt.1.a : Déclaration de l'élément 'beans' introuvable.
    at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
    at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:135)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
    at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2132)
    at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:829)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:613)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3063)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:836)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)
    at java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:77)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:435)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:393)
    ... 14 more

Can you help me solve my problem?


来源: stackexchange

问:
How to get ion-slide index on click?
I want to get slide index on click, I have ion-slides and its options are per page 2.5 slide. When I try to get active index it getting zero(0).

here my code

```<code>@ViewChild(IonSlides, { static: false }) slides: IonSlides;
slideOpts = {
  slidesPerView: 2.5,
  zoom: false,
  slideShadows: true
};

getIndex() {
    this.slides.getActiveIndex().then((index) => {
      this.currentIndex = index;
      console.log(this.currentIndex);
    })
}
</code>```

here my HTML

```<code><ion-slides [options]="slideOpts" #slides>
  <ion-slide *ngFor="let item of items">
    <p>{{item.name}}</p>
  </ion-slide>
</ion-slides>
</code>```

答:
I tried this and it logs slide index for me.

In HTML

```<code><ion-slides pager="true" #mySlider (ionSlidesDidLoad)="slidesDidLoad(mySlider)"
    (ionSlideTransitionEnd)="slideChanged(mySlider)">
<ion-slide (click)="getSlideIndex()"> ... </ion-slide>
</ion-slides>
</code>```

On your ts file

```<code>@ViewChild('mySlider', { static: true }) slider: IonSlides;

slidesDidLoad(slides: IonSlides) {
    slides.startAutoplay();
    slides.getActiveIndex().then(index => {
      console.log(index);
    });
  }

  slideChanged(slides: IonSlides) {
    slides.startAutoplay();
    slides.getActiveIndex().then(index => {
      console.log(index);
    });
  }

getSlideIndex(){ //updated
this.slider.getActiveIndex().then(index => {
      console.log(index);
    });
}
</code>```

Try it.

ContentLicense: CC BY-SA 4.0

Title: How to get ion-slide index on click?

Body:
I want to get slide index on click, I have ion-slides and its options are per page 2.5 slide. When I try to get active index it getting zero(0).

here my code

@ViewChild(IonSlides, { static: false }) slides: IonSlides;
slideOpts = {
  slidesPerView: 2.5,
  zoom: false,
  slideShadows: true
};

getIndex() {
    this.slides.getActiveIndex().then((index) => {
      this.currentIndex = index;
      console.log(this.currentIndex);
    })
}

here my HTML

<ion-slides [options]="slideOpts" #slides>
  <ion-slide *ngFor="let item of items">

{{item.name}}

  </ion-slide>
</ion-slides>

Body:
I tried this and it logs slide index for me.

In HTML

<ion-slides pager="true" #mySlider (ionSlidesDidLoad)="slidesDidLoad(mySlider)"
    (ionSlideTransitionEnd)="slideChanged(mySlider)">
<ion-slide (click)="getSlideIndex()"> ... </ion-slide>
</ion-slides>

On your ts file

@ViewChild('mySlider', { static: true }) slider: IonSlides;

slidesDidLoad(slides: IonSlides) {
    slides.startAutoplay();
    slides.getActiveIndex().then(index => {
      console.log(index);
    });
  }

  slideChanged(slides: IonSlides) {
    slides.startAutoplay();
    slides.getActiveIndex().then(index => {
      console.log(index);
    });
  }

getSlideIndex(){ //updated
this.slider.getActiveIndex().then(index => {
      console.log(index);
    });
}

Try it.


问:
Can any one explain the meaning of orderby line of SQL in below code?
Could anyone please explain the meaning of orderby line in below code?</p>

```<code>SELECT winner, subject
FROM nobel
WHERE year=1984
ORDER BY subject IN ('Chemistry', 'Physics'),subject,winner
</code>```

答:
This is a boolean expression:

```<code>subject IN ('Chemistry', 'Physics')
</code>```

In databases that support booleans, this evaluates to "true" or "false" or NULL.  In such databases, "true" is equivalent to 1 and "false" to 0.

Hence, this puts those subjects after all other subjects:

```<code>Literature     false  --> 0
Economics      false  --> 0
Chemistry      true   --> 1
Physics        true   --> 1
</code>```

The standard construct would use case:

```<code>order by (case when subject in ('Chemistry', 'Physics') then 1 else 0 end),
          . . .
</code>```

The use of booleans like this is fine.  However, I almost always use a desc sort so the TRUE values go first.

Body:
Could anyone please explain the meaning of orderby line in below code?

SELECT winner, subject
FROM nobel
WHERE year=1984
ORDER BY subject IN ('Chemistry', 'Physics'),subject,winner

Body:
This is a boolean expression:

subject IN ('Chemistry', 'Physics')

In databases that support booleans, this evaluates to "true" or "false" or NULL.  In such databases, "true" is equivalent to 1 and "false" to 0.

Hence, this puts those subjects after all other subjects:

Literature     false  --> 0
Economics      false  --> 0
Chemistry      true   --> 1
Physics        true   --> 1

The standard construct would use case:

order by (case when subject in ('Chemistry', 'Physics') then 1 else 0 end),
          . . .

The use of booleans like this is fine.  However, I almost always use a desc sort so the TRUE values go first.


问:
Postman - JWT authentication using key file
I am trying to use Postman to test API developed on Google Cloud Platform: App Engine behind an API endpoint.

I have the key file in the JSON format:

```<code>{
  "type": "service_account",
  "project_id": "[[my_project_name]]",
  "private_key_id": "[[private_key_id]]",
  "private_key": "-----BEGIN PRIVATE KEY-----\n[[private_key]]\n-----END PRIVATE KEY-----\n",
  "client_email": "[[service_account_email]]",
  "client_id": "",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[[service_account_email]]"
}
</code>```

And I am able to retrieve access token using python code:

```<code>import time
import google.auth.crypt
import google.auth.jwt

sa_keyfile='[[path_to_the_api_key_file]]'
sa_email='[[service_account_email]]'
audience='[[my_api_url]]'
expiry_length=3600
now = int(time.time())
payload = {
    'iat': now,
    "exp": now + expiry_length,
    'iss': sa_email,
    'aud':  audience,
    'sub': sa_email,
    'email': sa_email
}

signer = google.auth.crypt.RSASigner.from_service_account_file(sa_keyfile)
jwt = google.auth.jwt.encode(signer, payload)

print(jwt)
</code>```

If I setup in Postman OAuth 2.0 as authentication method and paste obtained JWT as Access Token then request is working just fine.

I would like to move whole JWT token operation into the Postman, without need to invoke Python code in advance. I tried to use Get New Access Token from Postman, but neither option supports JSON key file.

Is it possible to get JWT token from JSON key file using Postman only?

答:
There are several ways to authorize users in GCP. Essentially and google's preferred way is to use key pairs to sign a request and send it to google for applications authenticity and authorize JWT related to context. While there are many options explaining how to do it server side, you need to be aware that these credentials actually allow you to access platform itself. This is essentially oAuth workflow and JWT you can get different sources have different scopes which in turns allows you to call endpoints related to them.

For postman you follow simple oAuth Workflow mentioned in docs which is straight forward Creating client IDs

Of course you need to implement serverside parts to call platform API's as they should not be exposed directly, hence extra security is given to obtain signed requests while getting platform tokens.

If you want to authorize end users this is the right guide : Authenticating users
Same guide has other options on how to authorize other 'types' f application.

Assuming you are using OpenApi Specs as its standard way to access RESTFUL apis.
Google has extensive documentation on using specific authentication provider for using their services.

Choosing an Authentication Method

Each methods have their pros & cons and select most suitable method that use JWT with proper privileges.

Other Documentation can be found here Cloud Endpoints documentation

Body:
I am trying to use Postman to test API developed on Google Cloud Platform: App Engine behind an API endpoint.

I have the key file in the JSON format:

{
  "type": "service_account",
  "project_id": "[[my_project_name]]",
  "private_key_id": "[[private_key_id]]",
  "private_key": "-----BEGIN PRIVATE KEY-----\n[[private_key]]\n-----END PRIVATE KEY-----\n",
  "client_email": "[[service_account_email]]",
  "client_id": "",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[[service_account_email]]"
}

And I am able to retrieve access token using python code:

import time
import google.auth.crypt
import google.auth.jwt

sa_keyfile='[[path_to_the_api_key_file]]'
sa_email='[[service_account_email]]'
audience='[[my_api_url]]'
expiry_length=3600
now = int(time.time())
payload = {
    'iat': now,
    "exp": now + expiry_length,
    'iss': sa_email,
    'aud':  audience,
    'sub': sa_email,
    'email': sa_email
}

signer = google.auth.crypt.RSASigner.from_service_account_file(sa_keyfile)
jwt = google.auth.jwt.encode(signer, payload)

print(jwt)

If I setup in Postman OAuth 2.0 as authentication method and paste obtained JWT as Access Token then request is working just fine.

I would like to move whole JWT token operation into the Postman, without need to invoke Python code in advance. I tried to use Get New Access Token from Postman, but neither option supports JSON key file.

Is it possible to get JWT token from JSON key file using Postman only?


问:
Should I use PHP readfile() or SFTP connection to download file from my server through a web app?
I was thinking about replacing all my PHP readfile() function calls into SFTP connections request to download files from my server.

Is this safer ?

Note : my files are on the same server as the web app, so is this useless to pass through SFTP ?

Thank you for your concern.

答: "If they're on the same server, you don't necessary need SFTP. That's like using a FTP to browse files locally on your computer – Cid 29 mins ago"</p>


问:
How can I do a sequence-to-sequence model (RNN / LSTM) with Keras with fixed length data?
What I'm trying to do seems so simple, but I can't find any examples online. First, I'm not working in language, so all of the embedding stuff adds needless complexity to my task.

I have input, in the form of a (1, 1000) vector. They are time-series data, so I'll have 10 of them in sequence. Which, if I understand tensors correctly, gives me something of shape (10, 1, 1000), right?

I want to pass this through an RNN/LSTM and the output should be also of the same shape (10, 1, 1000). Namely, 10 vectors of 1000 dimensions each.

答:
The first thing you need is to know "what" you consider a sequence there.

What are the steps? Are they 10 time steps? Or are they 1000 time steps?

I'll initially assume you have 1000 time steps.

Then the next question is: what are the 10 things? Are they 10 different independent examples of the same nature? Or are they 10 parallel things of different nature (features) from the same example?

These questions are the most important part, you need to know if you have:

(10, 1000, 1): 10 individual examples, 1000 timesteps per example, measuring a single variable/feature

(1, 1000, 10): 1 long sequence, of 1000 timesteps, measuring 10 independent vars/veatures

You will need to divide your data in sliding windows because there are too few examples for the two cases above (there are many examples of how to do this online). If you don't, your model will overfit wildly.

Sliding windows you will turn the data into (more_examples, shorter_length, same_features)

(1000, 10, 1): 1000 different sequences of 10 time steps measuring a single var/feature

Good data, you're good to go

(1, 10, 1000): 1 single sequence of 10 time steps, measuring 1000 independent vars/features

I'm not sure this data could be trained, you don't have enough examples even if you try sliding windows

(10, 1, 1000): 10 individual examples, 1 timestep, measuring 1000 vars/features

(1000, 1, 10): 1000 different sequences of 1 time step  measuring ten vars.

The two cases above are not sequences for working with LSTM.

Once you decided this, then it's time to work:

Stack the input data correctly according to your case and start a model.

I'll consider you have data with the shape (samples, timesteps, features), then your model can go like:

```<code>inputs = Input((timesteps, features)) #or (None,features) for variable length
outputs = LSTM(any_units, return_sequences=True)(inputs)
.... can add more LSTM layers with different units, and return_sequences=True
.... can add Conv1D layers with padding='same', any number of filters
outputs = Dense(desired_features, activation=some_useful_activation)(outputs)
</code>```

Notice that your output is necessarily (samples, timesteps, desired_features). If you want a different final shape, reshape it outside the model.

Body:
The first thing you need is to know "what" you consider a sequence there.

What are the steps? Are they 10 time steps? Or are they 1000 time steps?

I'll initially assume you have 1000 time steps.

Then the next question is: what are the 10 things? Are they 10 different independent examples of the same nature? Or are they 10 parallel things of different nature (features) from the same example?

These questions are the most important part, you need to know if you have:

(10, 1000, 1): 10 individual examples, 1000 timesteps per example, measuring a single variable/feature

(1, 1000, 10): 1 long sequence, of 1000 timesteps, measuring 10 independent vars/veatures

You will need to divide your data in sliding windows because there are too few examples for the two cases above (there are many examples of how to do this online). If you don't, your model will overfit wildly.

Sliding windows you will turn the data into (more_examples, shorter_length, same_features)

(1000, 10, 1): 1000 different sequences of 10 time steps measuring a single var/feature

Good data, you're good to go

(1, 10, 1000): 1 single sequence of 10 time steps, measuring 1000 independent vars/features

I'm not sure this data could be trained, you don't have enough examples even if you try sliding windows

(10, 1, 1000): 10 individual examples, 1 timestep, measuring 1000 vars/features

(1000, 1, 10): 1000 different sequences of 1 time step  measuring ten vars.

The two cases above are not sequences for working with LSTM.

Once you decided this, then it's time to work:

Stack the input data correctly according to your case and start a model.

I'll consider you have data with the shape (samples, timesteps, features), then your model can go like:

inputs = Input((timesteps, features)) #or (None,features) for variable length
outputs = LSTM(any_units, return_sequences=True)(inputs)
.... can add more LSTM layers with different units, and return_sequences=True
.... can add Conv1D layers with padding='same', any number of filters
outputs = Dense(desired_features, activation=some_useful_activation)(outputs)

Notice that your output is necessarily (samples, timesteps, desired_features). If you want a different final shape, reshape it outside the model.


问:
Stratified Sampling in Python without using any Machine Learning
I have a dataset that contains : ("wordsList" and "classList" file).

wordsList file contains 72 pre-processed emails. Each line is a list of words extracted from each email.

The classList file contains the class labels that indicating whether the emails are ordinary or adverts (0 for ordinary and 1 for adverts).

My task is to develop a Naïve Bayesian classifier as an email filter in Python. Namely, the classifier predicts whether emails are ordinary or adverts.

To develop this I need to use stratified sampling to select 66 out of 72 lines for training and the remaining 6 lines for the test. Then return the classification probabilities of these 6 records.
But the bad news for me is that I can't use any machine learning library, and only can use NumPy and SciPy.

Is there any way to implement this? And if so is there any sample code that implements this method from scratch? Thank you in advance!

答:
The simplest solution is to use the groupby method of  pandas and then to apply sampling with frac=0.91 to get 66 lines out of the 72 in your case:

```<code>cL2=cL.groupby(['classList']).apply(lambda x: x.sample(frac=0.91))
</code>```

This creates a MultiIndex dataframe that is turned to a normal one by reseting index, dropping the column 'classList' associated to the groupby method, and optionally dropping an extra one (named in reference to the number of grouping variables, level_1 here):

```<code>cL3=cL2.drop(columns=['classList']).reset_index().drop(columns=['level_1'])

</code>```

Body:
The simplest solution is to use the groupby method of  pandas and then to apply sampling with frac=0.91 to get 66 lines out of the 72 in your case:

cL2=cL.groupby(['classList']).apply(lambda x: x.sample(frac=0.91))

This creates a MultiIndex dataframe that is turned to a normal one by reseting index, dropping the column 'classList' associated to the groupby method, and optionally dropping an extra one (named in reference to the number of grouping variables, level_1 here):

cL3=cL2.drop(columns=['classList']).reset_index().drop(columns=['level_1'])


问:
Dapper data serialization problem on Dot Net Core 3.0
I have a strange error with Dapper (2.0.30) on new DotNet Core 3.0.

I am trying to load data from database with this command:

```<code>await connection.QueryAsync(command)).AsList()
</code>```

And I want to return result as json

```<code>return this.Ok(Database.Load("SELECT * FROM table_name;"));
</code>```

But I am getting this strange error:

```<code>System.InvalidCastException: Unable to cast object of type '<GetEnumerator>d__9' to type 'System.Collections.IDictionaryEnumerator'.
   at System.Text.Json.JsonSerializer.HandleDictionary(JsonClassInfo elementClassInfo, JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack& state)
   at System.Text.Json.JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.JsonSerializer.WriteAsyncCore(Stream utf8Json, Object value, Type inputType, JsonSerializerOptions options, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
   at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultAsync>g__Logged|21_0(ResourceInvoker invoker, IActionResult result)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultFilters>g__Awaited|27_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
</code>```

I tried exact same code on DotNet 2.0 and it worked. I guess that it has something to do with new build in json serialize, that is not compatible with dapper or something?

I looked up on internet but I could not find much (nothing actually) about this.
Just this quote from this website

This looks like a bug in how we deal with types that implement
  IDictionary where we expect such types to return an
  enumerator that implements IDictionaryEnumerator (and types like
  DapperRow don't implement that interface).

```<code>System.Text.Json.Serialization.Tests.ValueTests.DapperTest [FAIL]
        System.InvalidCastException : Unable to cast object of type '<GetEnumerator>d__9' to type 'System.Collections.IDictionaryEnumerator'.
        Stack Trace:
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.HandleDictionary.cs(64,0): at System.Text.Json.JsonSerializer.HandleDictionary(JsonClassInfo elementClassInfo, JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack& state)
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.cs(40,0): at System.Text.Json.JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack& state)
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.Helpers.cs(131,0): at System.Text.Json.JsonSerializer.WriteCore(Utf8JsonWriter writer, Object value, Type type, JsonSerializerOptions options)
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.Helpers.cs(107,0): at System.Text.Json.JsonSerializer.WriteCore(PooledByteBufferWriter output, Object value, Type type, JsonSerializerOptions options)
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.Helpers.cs(86,0): at System.Text.Json.JsonSerializer.WriteCoreString(Object value, Type type, JsonSerializerOptions options)
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.String.cs(21,0): at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
          E:\GitHub\Fork\corefx\src\System.Text.Json\tests\Serialization\Value.WriteTests.cs(47,0): at System.Text.Json.Serialization.Tests.ValueTests.DapperTest()
</code>```

Therefore, we are failing at this cast, since the enumerator that
  DapperRow returns is IEnumerator> and not
  IDictionaryEnumerator:
  https://github.com/dotnet/corefx/blob/b832f6ccdebd18469e4b6d03c1c9b2c9c6c14374/src/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.HandleDictionary.cs#L64

Does anyone knows how to make it work?
Thanks

Update:

I kinda fix it.

First I added libary from nudget Microsoft.AspNetCore.Mvc.NewtonsoftJson.
And added Newtonsoft as default json middleware.

```<code>services.AddMvc()
    .AddNewtonsoftJson();
</code>```

And

```<code>services.AddControllers()
    .AddNewtonsoftJson();
</code>```

But I still dont know why it did not run out of box, as it was on previous version of DotNet core.

答:
As you can read in the following documentation that describes how to migrate from Asp.net core 2.2 to version 3:

The default JSON serializer for ASP.NET Core is now System.Text.Json,
  which is new in .NET Core 3.0. Consider using System.Text.Json when
  possible. It's high-performance and doesn't require an additional
  library dependency. However, since System.Text.Json is new, it might
  currently be missing features that your app needs

Maybe the new serializer doesn't support this feature yet

https://learn.microsoft.com/en-US/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio

Body:
I have a strange error with Dapper (2.0.30) on new DotNet Core 3.0.

I am trying to load data from database with this command:

await connection.QueryAsync(command)).AsList()

And I want to return result as json

return this.Ok(Database.Load("SELECT * FROM table_name;"));

But I am getting this strange error:

System.InvalidCastException: Unable to cast object of type '<GetEnumerator>d__9' to type 'System.Collections.IDictionaryEnumerator'.
   at System.Text.Json.JsonSerializer.HandleDictionary(JsonClassInfo elementClassInfo, JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack& state)
   at System.Text.Json.JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.JsonSerializer.WriteAsyncCore(Stream utf8Json, Object value, Type inputType, JsonSerializerOptions options, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
   at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultAsync>g__Logged|21_0(ResourceInvoker invoker, IActionResult result)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultFilters>g__Awaited|27_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I tried exact same code on DotNet 2.0 and it worked. I guess that it has something to do with new build in json serialize, that is not compatible with dapper or something?

I looked up on internet but I could not find much (nothing actually) about this.
Just this quote from this website

This looks like a bug in how we deal with types that implement
  IDictionary where we expect such types to return an
  enumerator that implements IDictionaryEnumerator (and types like
  DapperRow don't implement that interface).

System.Text.Json.Serialization.Tests.ValueTests.DapperTest [FAIL]
        System.InvalidCastException : Unable to cast object of type '<GetEnumerator>d__9' to type 'System.Collections.IDictionaryEnumerator'.
        Stack Trace:
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.HandleDictionary.cs(64,0): at System.Text.Json.JsonSerializer.HandleDictionary(JsonClassInfo elementClassInfo, JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack& state)
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.cs(40,0): at System.Text.Json.JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack& state)
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.Helpers.cs(131,0): at System.Text.Json.JsonSerializer.WriteCore(Utf8JsonWriter writer, Object value, Type type, JsonSerializerOptions options)
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.Helpers.cs(107,0): at System.Text.Json.JsonSerializer.WriteCore(PooledByteBufferWriter output, Object value, Type type, JsonSerializerOptions options)
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.Helpers.cs(86,0): at System.Text.Json.JsonSerializer.WriteCoreString(Object value, Type type, JsonSerializerOptions options)
          E:\GitHub\Fork\corefx\src\System.Text.Json\src\System\Text\Json\Serialization\JsonSerializer.Write.String.cs(21,0): at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
          E:\GitHub\Fork\corefx\src\System.Text.Json\tests\Serialization\Value.WriteTests.cs(47,0): at System.Text.Json.Serialization.Tests.ValueTests.DapperTest()

Therefore, we are failing at this cast, since the enumerator that
  DapperRow returns is IEnumerator> and not
  IDictionaryEnumerator:
  https://github.com/dotnet/corefx/blob/b832f6ccdebd18469e4b6d03c1c9b2c9c6c14374/src/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.HandleDictionary.cs#L64

Does anyone knows how to make it work?
Thanks

Update:

I kinda fix it.

First I added libary from nudget Microsoft.AspNetCore.Mvc.NewtonsoftJson.
And added Newtonsoft as default json middleware.

services.AddMvc()
    .AddNewtonsoftJson();

And

services.AddControllers()
    .AddNewtonsoftJson();

But I still dont know why it did not run out of box, as it was on previous version of DotNet core.


问:
Check how many of the same chars line op in list
I have a python list,

```<code>l=[0,1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
</code>```

for example,
I want to check if the list contain at least 7 1's next to each other.

I'm not sure how to check this.

to clarify:

```<code>a=[0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 ] #should return True
b=[0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0 ] #should return False
</code>```

Any ideas?

答:
you can check if any sublist of 7 elements match with a list of 7 of 1:

```<code>def f(l):
    pat = [1] * 7
    for i in range(len(l)-7):
        if l[i: i+7] == pat:
            return True

    return False

</code>```

same idea in the following one-line code:

```<code>[1] * 7 in (l[i:i+7] for i in range(len(l) - 7))
</code>```

Body:
I have a python list,

l=[0,1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]

for example,
I want to check if the list contain at least 7 1's next to each other.

I'm not sure how to check this.

to clarify:

a=[0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 ] #should return True
b=[0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0 ] #should return False

Any ideas?

Body:
you can check if any sublist of 7 elements match with a list of 7 of 1:

def f(l):
    pat = [1] * 7
    for i in range(len(l)-7):
        if l[i: i+7] == pat:
            return True

    return False

same idea in the following one-line code:

[1] * 7 in (l[i:i+7] for i in range(len(l) - 7))


问:
How to set value for provider gathered from API backend in Angular
how can I set value here from API ?

答:
You could use a factory

In a module initialize the service and call the API

```<code>
export function setupFactory(myService:MyService) {
  return () => myService.load();
}

@NgModule({
  declarations: [
    AppComponent,
    TestComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [
    { provide: APP_INITIALIZER,  useFactory: setupFactory, deps: [MyService], multi: true }, ],
  bootstrap: [AppComponent]
})
export class AppModule { }
</code>```

Then you can call a function to get the API key

```<code>@Injectable({ providedIn: 'root'})
export class MyService {

  private _apiKey = '';

  public apiKey(): string {
    return this._apiKey;
  }

  public async load() {
    // Simulate calling the API
    this._apiKey = await new Promise((r) => {
      r('you api key')
    })
  }
}

let apiFactory = (MyService: MyService) => {
  return MyService.apiKey();
}

providers: [{ provide: 'googleTagManagerId',  useFactory: apiFactory, deps: [MyService] }]

</code>```

Body: how can I set value here from API ?

Body:
You could use a factory

In a module initialize the service and call the API

export function setupFactory(myService:MyService) {
  return () => myService.load();
}

@NgModule({
  declarations: [
    AppComponent,
    TestComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [
    { provide: APP_INITIALIZER,  useFactory: setupFactory, deps: [MyService], multi: true }, ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Then you can call a function to get the API key

@Injectable({ providedIn: 'root'})
export class MyService {

  private _apiKey = '';

  public apiKey(): string {
    return this._apiKey;
  }

  public async load() {
    // Simulate calling the API
    this._apiKey = await new Promise((r) => {
      r('you api key')
    })
  }
}

let apiFactory = (MyService: MyService) => {
  return MyService.apiKey();
}

providers: [{ provide: 'googleTagManagerId',  useFactory: apiFactory, deps: [MyService] }]


问:
How do you load .js files with ASP.NET?
```<code><%@ Page Language="VB"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
  <script runat="server">

Sub Page_Load(ByVal e As System.EventArgs)
Page.ClientScript.RegisterClientScriptInclude("basicjs", "basic.js")
End Sub

</script>
    <title>RegisterClientScriptBlock Example</title>
  </head>
  <body>
<form runat="server">
    <input type="button" id="button1" value="clickme" onclick="click()"/>
</form>
  </body>
</html>
</code>```

I'm using ASP.net (just learning) with VB. I can't seem to get Javascript code to work with ASP VB code. My main problem seems to be that .js files are not loading. In the example, basic.js just contains a function click() that calls an alert() message. How do I get .js files to load with ASP code?

答:
It should be like...</p>

```<code>Page.ClientScript.RegisterClientScriptInclude("JScripts", ResolveUrl("~/JSFolderName/basic.js"));
</code>```

ContentLicense: CC BY-SA 3.0

Title: How do you load .js files with ASP.NET?

Body:
<%@ Page Language="VB"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <title>RegisterClientScriptBlock Example</title>

<form runat="server">
    <input type="button" id="button1" value="clickme" onclick="click()"/>
</form>

I'm using ASP.net (just learning) with VB. I can't seem to get Javascript code to work with ASP VB code. My main problem seems to be that .js files are not loading. In the example, basic.js just contains a function click() that calls an alert() message. How do I get .js files to load with ASP code?

Body:
It should be like...

Page.ClientScript.RegisterClientScriptInclude("JScripts", ResolveUrl("~/JSFolderName/basic.js"));


问:
How to logout from ASP.NET web application, if webapi token based authentication reaches it's expire time
My web application is using web api which is token based authentication. Its expire time is set as one hour. How can I check it in my app and set the system to logout when reaches this expire time? </p>

```<code>   var OAuthOptions = new OAuthAuthorizationServerOptions
        {
            AllowInsecureHttp = true,
            TokenEndpointPath = new PathString("/token"),
            AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(60),
            Provider = new SimpleAuthorizationServerProvider()
        };

 {
"access_token": "GjNT5eNHOxwp1JRnEveHo_ensDBCoLkhZ5jBgN2hR_tYOU7_lRXtdKav12KUTXBHtuzc22i21j9oNve0h0lh1L8YcPfrzdzGExcCVKNvXqSv6HTGA1YOn99uwGFWj3o6SNLwz4_2ljA0QnX1QFkM4NJ9HtMxWKROOeqBr87ODZFWZh1Tc4wNv7PGVX8G6OMj12Q0mQ",
"token_type": "bearer",
"expires_in": 3599
 }
</code>```

答:
I suppose you are using HttpClient. So when reading the HttpResponseMessage, you can get the status code in the response and based on it, perform an action.
You can find all status codes in:
HttpStatusCode

For the outdated token, it'll return 401 Unauthorized which means the user has to login again to get a new token. So reading the status code 401 will determine the token status.

Body:
My web application is using web api which is token based authentication. Its expire time is set as one hour. How can I check it in my app and set the system to logout when reaches this expire time?

   var OAuthOptions = new OAuthAuthorizationServerOptions
        {
            AllowInsecureHttp = true,
            TokenEndpointPath = new PathString("/token"),
            AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(60),
            Provider = new SimpleAuthorizationServerProvider()
        };

 {
"access_token": "GjNT5eNHOxwp1JRnEveHo_ensDBCoLkhZ5jBgN2hR_tYOU7_lRXtdKav12KUTXBHtuzc22i21j9oNve0h0lh1L8YcPfrzdzGExcCVKNvXqSv6HTGA1YOn99uwGFWj3o6SNLwz4_2ljA0QnX1QFkM4NJ9HtMxWKROOeqBr87ODZFWZh1Tc4wNv7PGVX8G6OMj12Q0mQ",
"token_type": "bearer",
"expires_in": 3599
 }


问:
Check if at least two elements in an array are greater than zero - JavaScript/Typescript
Is there a smart way to find out if there are at least two values greater than 0 in an array and return true? And false in the opposite case?

(hypothetical and wrong example using some):

```<code>const a = [9, 1, 0];
const b = [0, 0, 0];
const c = [5, 0, 0];

const cond = (el) => el > 0 && somethingElseMaybe;

console.log(a.some(cond)); // print true
console.log(b.some(cond)); // print false
console.log(c.some(cond)); // print false

</code>```

答:
Try that

var a = [9, 1, 0]
var b = [0, 0, 0]
var c = [5, 0, 0]

function atLeastTwoEntries(arr, entrie) {
  return arr.indexOf(entrie) !== arr.lastIndexOf(entrie)
}

console.log(atLeastTwoEntries(a, 0))
console.log(atLeastTwoEntries(b, 0))
console.log(atLeastTwoEntries(c, 0))```

Body:
Is there a smart way to find out if there are at least two values greater than 0 in an array and return true? And false in the opposite case?

(hypothetical and wrong example using some):

const a = [9, 1, 0];
const b = [0, 0, 0];
const c = [5, 0, 0];

const cond = (el) => el > 0 && somethingElseMaybe;

console.log(a.some(cond)); // print true
console.log(b.some(cond)); // print false
console.log(c.some(cond)); // print false


问:
Store Values from Material UI's form in TypeScript
What's the best way to store values typed into the text fields here?

```<code>const AddUserPage = () => (
  <div>
    <PermanentDrawerLeft></PermanentDrawerLeft>
    <div className='main-content'>
    <form className="ROOT" noValidate autoComplete="off">
      <TextField id="standard-basic" label="Standard" />
    </form>
    </div>
  </div>
);

export default AddUserPage;
</code>```

I want to find a way such that I can use the stored values in my GraphQL mutations as well, without having to modify the const() structure of my page. I don't want to use the Class Component Extend or function structure here.

答:
What is your const() structuremakes:

=> (This is the auto return syntax.)

If you want to store/reuse your value, you will have to define some state/variable to store the data.
You can also do it in upper component like:

```<code>import React, { useState } from "react";

const Parent = props => {
  const [state, setState] = useState({ text: "" });
  return <AddUserPage value={state.text} onChange={e => setState(prev => ({ ...prev, text: e.target.value || "" }))} />
}

const AddUserPage = ({ value = "" , onChange }) => (
  <div>
    <PermanentDrawerLeft></PermanentDrawerLeft>
    <div className='main-content'>
    <form className="ROOT" noValidate autoComplete="off">
      <TextField id="standard-basic" value={value} onChange={onChange} label="Standard" />
     // value, and Onchange comes from an upper component
    </form>
    </div>
  </div>
);
</code>```

Body:
What's the best way to store values typed into the text fields here?

const AddUserPage = () => (

    <PermanentDrawerLeft></PermanentDrawerLeft>

    <form className="ROOT" noValidate autoComplete="off">
      <TextField id="standard-basic" label="Standard" />
    </form>

);

export default AddUserPage;

I want to find a way such that I can use the stored values in my GraphQL mutations as well, without having to modify the const() structure of my page. I don't want to use the Class Component Extend or function structure here.

Body:
What is your const() structuremakes:

=> (This is the auto return syntax.)

If you want to store/reuse your value, you will have to define some state/variable to store the data.
You can also do it in upper component like:

import React, { useState } from "react";

const Parent = props => {
  const [state, setState] = useState({ text: "" });
  return <AddUserPage value={state.text} onChange={e => setState(prev => ({ ...prev, text: e.target.value || "" }))} />
}

const AddUserPage = ({ value = "" , onChange }) => (
  <div>
    <PermanentDrawerLeft></PermanentDrawerLeft>
    <div className='main-content'>
    <form className="ROOT" noValidate autoComplete="off">
      <TextField id="standard-basic" value={value} onChange={onChange} label="Standard" />
     // value, and Onchange comes from an upper component
    </form>
    </div>
  </div>
);


问:
Problem scraping website using Java Jsoup, website not "scrolling"
My question is about the possibility of scraping data from particular websites.
At the moment, my algorithm is converting HTML to text, then checking for flagged words that are contained in a file,
and summing up the number of flags.

My problem lies in the inability to "scroll" down while scraping the website.
As you can see, it's checking the number of flags on a twitter account, but it is limited to 50sh latest tweets.
I hope I made myself clear.

ps: I gave twitter as an example, and I'm not looking for something specific for twitter, but something more robust.

I will greatly appreciate any hints.

Sample output:

DHS & Other Agencies:           0 instances

Domestic security:          1 instances

HAZMAT & Nuclear:           0 instances

Health Concern + H1N1:          0 instances

Infrastructure Security:        2 instances

Southwest Border Violence:      1 instances

Terrorism:              0 instances

Weather/Disaster/Emergency:     2 instances

Cyber Security:             0 instances

TOTAL FLAGS:                6 instances

```<code>import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.*;
import java.util.LinkedList;
import java.util.List;

public class Main {

static List<String> dhsAndOtherAgencies = new LinkedList<>();
static List<String> domesticSecurity = new LinkedList<>();
static List<String> hazmatNuclear = new LinkedList<>();
static List<String> healthConcern = new LinkedList<>();
static List<String> infrastructureSecurity = new LinkedList<>();
static List<String> southwestBorderViolence = new LinkedList<>();
static List<String> terrorism = new LinkedList<>();
static List<String> weatherDisasterEmergency = new LinkedList<>();
static List<String> cyberSecutiry = new LinkedList<>();
static String stream;

public static void main(String[] args) throws IOException {

    createLists();
    createStream();
    Raport raport = generateReport();
    System.out.println(raport);

}

static int flagStream(List<String> list, String stream){

    int counter = 0;
    for (String flag: list){
        if(stream.contains(flag)) {
            System.out.println(flag);
            counter++;
        }
    }

    return counter;
}

static Raport generateReport(){
    return new Raport(
            flagStream(dhsAndOtherAgencies,stream),
            flagStream(domesticSecurity,stream),
            flagStream(hazmatNuclear,stream),
            flagStream(healthConcern,stream),
            flagStream(infrastructureSecurity,stream),
            flagStream(southwestBorderViolence,stream),
            flagStream(terrorism,stream),
            flagStream(weatherDisasterEmergency,stream),
            flagStream(cyberSecutiry,stream)

    );

}
static void createStream() throws IOException {
    Document doc = Jsoup.connect("https://twitter.com/realDonaldTrump").userAgent("mozilla/17.0").get();
    stream = doc.text();
}
static void createLists() throws IOException {
    BufferedReader read = new BufferedReader(new FileReader("clearListAllCases.txt"));

    String input;

    int hashCounter = 0;

    while((input=read.readLine())!=null){
        if(input.charAt(0)=='#'){
            hashCounter++;
            continue;
        }
        switch (hashCounter){

            case 1:
                dhsAndOtherAgencies.add(input);
                break;
            case 2:
                domesticSecurity.add(input);
                break;
            case 3:
                hazmatNuclear.add(input);
                break;
            case 4:
                healthConcern.add(input);
                break;
            case 5:
                infrastructureSecurity.add(input);
                break;
            case 6:
                southwestBorderViolence.add(input);
                break;
            case 7:
                terrorism.add(input);
                break;
            case 8:
                weatherDisasterEmergency.add(input);
                break;
            case 9:
                cyberSecutiry.add(input);
                break;
        }
    }
}
}

 class Raport {

int a,b,c,d,e,f,g,h,i;
int totalFlags;

Raport(int a, int b, int c, int d, int e, int f, int g, int h, int i){
    this.a = a;
    this.b = b;
    this.c = c;
    this.d = d;
    this.e = e;
    this.f = f;
    this.g = g;
    this.h = h;
    this.i = i;
    totalFlags = a+b+c+d+e+f+g+h+i;
}

public String toString(){

    return "DHS & Other Agencies:\t\t\t"+a+" instances\n"+
            "Domestic security:\t\t\t\t"+b+" instances\n"+
            "HAZMAT & Nuclear:\t\t\t\t"+c+" instances\n"+
            "Health Concern + H1N1:\t\t\t"+d+" instances\n"+
            "Infrastructure Security:\t\t"+e+" instances\n"+
            "Southwest Border Violence:\t\t"+f+" instances\n"+
            "Terrorism:\t\t\t\t\t\t"+g+" instances\n"+
            "Weather/Disaster/Emergency:\t\t"+h+" instances\n"+
            "Cyber Security:\t\t\t\t\t"+i+" instances\n"+
            "TOTAL FLAGS:\t\t\t\t\t"+totalFlags+" instances";
}
</code>```

}

答:
I would suggest opening the browser's developer tab for trying to find out which url/endpoint the website uses for fetching new items for the infinite scroll, as JSoup does not execute Javascript itself. Then you can call the endpoint with JSoup and parse the results.

In case it does not work, It would be probably better to move to HtmlUnit or Selenium as both of them are full-featured web browser APIs which you can control with Java.

Body:
My question is about the possibility of scraping data from particular websites.
At the moment, my algorithm is converting HTML to text, then checking for flagged words that are contained in a file,
and summing up the number of flags.

My problem lies in the inability to "scroll" down while scraping the website.
As you can see, it's checking the number of flags on a twitter account, but it is limited to 50sh latest tweets.
I hope I made myself clear.

ps: I gave twitter as an example, and I'm not looking for something specific for twitter, but something more robust.

I will greatly appreciate any hints.

Sample output:

DHS & Other Agencies:           0 instances

Domestic security:          1 instances

HAZMAT & Nuclear:           0 instances

Health Concern + H1N1:          0 instances

Infrastructure Security:        2 instances

Southwest Border Violence:      1 instances

Terrorism:              0 instances

Weather/Disaster/Emergency:     2 instances

Cyber Security:             0 instances

TOTAL FLAGS:                6 instances

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.*;
import java.util.LinkedList;
import java.util.List;

public class Main {

static List<String> dhsAndOtherAgencies = new LinkedList<>();
static List<String> domesticSecurity = new LinkedList<>();
static List<String> hazmatNuclear = new LinkedList<>();
static List<String> healthConcern = new LinkedList<>();
static List<String> infrastructureSecurity = new LinkedList<>();
static List<String> southwestBorderViolence = new LinkedList<>();
static List<String> terrorism = new LinkedList<>();
static List<String> weatherDisasterEmergency = new LinkedList<>();
static List<String> cyberSecutiry = new LinkedList<>();
static String stream;

public static void main(String[] args) throws IOException {

    createLists();
    createStream();
    Raport raport = generateReport();
    System.out.println(raport);

}

static int flagStream(List<String> list, String stream){

    int counter = 0;
    for (String flag: list){
        if(stream.contains(flag)) {
            System.out.println(flag);
            counter++;
        }
    }

    return counter;
}

static Raport generateReport(){
    return new Raport(
            flagStream(dhsAndOtherAgencies,stream),
            flagStream(domesticSecurity,stream),
            flagStream(hazmatNuclear,stream),
            flagStream(healthConcern,stream),
            flagStream(infrastructureSecurity,stream),
            flagStream(southwestBorderViolence,stream),
            flagStream(terrorism,stream),
            flagStream(weatherDisasterEmergency,stream),
            flagStream(cyberSecutiry,stream)

    );

}
static void createStream() throws IOException {
    Document doc = Jsoup.connect("https://twitter.com/realDonaldTrump").userAgent("mozilla/17.0").get();
    stream = doc.text();
}
static void createLists() throws IOException {
    BufferedReader read = new BufferedReader(new FileReader("clearListAllCases.txt"));

    String input;

    int hashCounter = 0;

    while((input=read.readLine())!=null){
        if(input.charAt(0)=='#'){
            hashCounter++;
            continue;
        }
        switch (hashCounter){

            case 1:
                dhsAndOtherAgencies.add(input);
                break;
            case 2:
                domesticSecurity.add(input);
                break;
            case 3:
                hazmatNuclear.add(input);
                break;
            case 4:
                healthConcern.add(input);
                break;
            case 5:
                infrastructureSecurity.add(input);
                break;
            case 6:
                southwestBorderViolence.add(input);
                break;
            case 7:
                terrorism.add(input);
                break;
            case 8:
                weatherDisasterEmergency.add(input);
                break;
            case 9:
                cyberSecutiry.add(input);
                break;
        }
    }
}
}

 class Raport {

int a,b,c,d,e,f,g,h,i;
int totalFlags;

Raport(int a, int b, int c, int d, int e, int f, int g, int h, int i){
    this.a = a;
    this.b = b;
    this.c = c;
    this.d = d;
    this.e = e;
    this.f = f;
    this.g = g;
    this.h = h;
    this.i = i;
    totalFlags = a+b+c+d+e+f+g+h+i;
}

public String toString(){

    return "DHS & Other Agencies:\t\t\t"+a+" instances\n"+
            "Domestic security:\t\t\t\t"+b+" instances\n"+
            "HAZMAT & Nuclear:\t\t\t\t"+c+" instances\n"+
            "Health Concern + H1N1:\t\t\t"+d+" instances\n"+
            "Infrastructure Security:\t\t"+e+" instances\n"+
            "Southwest Border Violence:\t\t"+f+" instances\n"+
            "Terrorism:\t\t\t\t\t\t"+g+" instances\n"+
            "Weather/Disaster/Emergency:\t\t"+h+" instances\n"+
            "Cyber Security:\t\t\t\t\t"+i+" instances\n"+
            "TOTAL FLAGS:\t\t\t\t\t"+totalFlags+" instances";
}

}