SpringBoot integrated Quartz timing task
1, create project



2. Create task class
package com.quartzjob.job.sysJob;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 具体任务
*/
public class HelloJob implements Job {
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss");
String dateString = simpleDateFormat.format(date);
System.out.println(dateString);
}
}
3, configure trigger and task scheduler
package com.quartzjob.job.config;
import com.quartzjob.job.sysJob.HelloJob;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;
/**
* 配置触发器和任务调度器
*/
@Configuration
public class QuartzConfig {
/**
* 创建job对象
* @return
*/
@Bean
public JobDetailFactoryBean jobDetailFactoryBean(){
JobDetailFactoryBean factoryBean = new JobDetailFactoryBean();
//具体任务类
factoryBean.setJobClass(HelloJob.class);
return factoryBean;
}
/**
* 创建tigger对象
* @param jobDetailFactoryBean
* @return
*/
@Bean
public SimpleTriggerFactoryBean simpleTriggerFactoryBean(JobDetailFactoryBean jobDetailFactoryBean){
SimpleTriggerFactoryBean factoryBean = new SimpleTriggerFactoryBean();
//关联jobDetailFactoryBean
factoryBean.setJobDetail(jobDetailFactoryBean.getObject());
//执行周期
factoryBean.setRepeatInterval(2000);
//重复次数
factoryBean.setRepeatCount(5);
return factoryBean;
}
/**
* 创建Scheduler
* @param simpleTriggerFactoryBean
* @return
*/
@Bean
public SchedulerFactoryBean schedulerFactoryBean(SimpleTriggerFactoryBean simpleTriggerFactoryBean){
SchedulerFactoryBean factoryBean = new SchedulerFactoryBean();
//关联tigger
factoryBean.setTriggers(simpleTriggerFactoryBean.getObject());
return factoryBean;
}
}
4. Turn on the timed task
package com.quartzjob.job;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class JobApplication {
public static void main(String[] args) {
SpringApplication.run(JobApplication.class, args);
}
}
div>
Type definition error – one of the causes of type definition errors is WM in Oracle_ Concat function usage
today for code development to meet the Type definition error: [simple Type, class oracle JDBC. OracleConnection]; Nested-exception is… After checking all the data, I finally found that it was caused by the wm_concat() function in Oracle. Wm_concat () will return different field types depending on the oracle version. Clob type will be returned in oracle11g and varchar type will be returned in oracle10g.
the solution is as follows:
select qlrid,to_char(wm_concat(qlr)) as qlr,to_char(wm_concat(qlrzjh)) as qlrzjh from qlr t group by qlrid;
div>
Java String.split () special character processing
introduction h1>
- JDK 1.8 li> ul>
split function h1>
notice that the split function takes a regular expression as an argument. The split function is defined as:
/**
* Splits this string around matches of the given <a
* href="../util/regex/Pattern.html#sum">regular expression</a>.
*
* <p> This method works as if by invoking the two-argument {@link
* #split(String, int) split} method with the given expression and a limit
* argument of zero. Trailing empty strings are therefore not included in
* the resulting array.
*
* <p> The string {@code "boo:and:foo"}, for example, yields the following
* results with these expressions:
*
* <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
* <tr>
* <th>Regex</th>
* <th>Result</th>
* </tr>
* <tr><td align=center>:</td>
* <td>{@code { "boo", "and", "foo" }}</td></tr>
* <tr><td align=center>o</td>
* <td>{@code { "b", "", ":and:f" }}</td></tr>
* </table></blockquote>
*
*
* @param regex
* the delimiting regular expression
*
* @return the array of strings computed by splitting this string
* around matches of the given regular expression
*
* @throws PatternSyntaxException
* if the regular expression's syntax is invalid
*
* @see java.util.regex.Pattern
*
* @since 1.4
* @spec JSR-51
*/
public String[] split(String regex) { ... }
special symbol processing
The
split function takes a regular expression as an argument, so special processing is required when the special symbol of the regular expression is used as a delimiter.
For example, . is a wildcard in regular expressions, and matches any single character except for line breaks (\n, \r).
can be handled in two ways for special symbols:
- escaped. For example,
\.
- put it in brackets. For example, the
[.] code> li> ul>
Example
h1>
String[] s1 = "a.b.c".split("\\.");
System.out.println(Arrays.asList(s1)); //[a, b, c]
String[] s2 = "a.b.c".split("[.]");
System.out.println(Arrays.asList(s2)); //[a, b, c]
Reference
h1>
https://www.runoob.com/regexp/regexp-metachar.html
split function h1>
notice that the split function takes a regular expression as an argument. The split function is defined as:
/**
* Splits this string around matches of the given <a
* href="../util/regex/Pattern.html#sum">regular expression</a>.
*
* <p> This method works as if by invoking the two-argument {@link
* #split(String, int) split} method with the given expression and a limit
* argument of zero. Trailing empty strings are therefore not included in
* the resulting array.
*
* <p> The string {@code "boo:and:foo"}, for example, yields the following
* results with these expressions:
*
* <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
* <tr>
* <th>Regex</th>
* <th>Result</th>
* </tr>
* <tr><td align=center>:</td>
* <td>{@code { "boo", "and", "foo" }}</td></tr>
* <tr><td align=center>o</td>
* <td>{@code { "b", "", ":and:f" }}</td></tr>
* </table></blockquote>
*
*
* @param regex
* the delimiting regular expression
*
* @return the array of strings computed by splitting this string
* around matches of the given regular expression
*
* @throws PatternSyntaxException
* if the regular expression's syntax is invalid
*
* @see java.util.regex.Pattern
*
* @since 1.4
* @spec JSR-51
*/
public String[] split(String regex) { ... }
special symbol processing
The
split function takes a regular expression as an argument, so special processing is required when the special symbol of the regular expression is used as a delimiter.
For example, . is a wildcard in regular expressions, and matches any single character except for line breaks (\n, \r).
can be handled in two ways for special symbols:
- escaped. For example,
\. - put it in brackets. For example, the
[.] code> li> ul>
Exampleh1>
String[] s1 = "a.b.c".split("\\."); System.out.println(Arrays.asList(s1)); //[a, b, c] String[] s2 = "a.b.c".split("[.]"); System.out.println(Arrays.asList(s2)); //[a, b, c]Reference
h1>
https://www.runoob.com/regexp/regexp-metachar.html
Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing a block collection
Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:D:\LANCE_SYSTEM_TOOLS\Tools\After_Tools\JetBrains\IntelliJIDEA2020.1.1\lib\idea_rt.jar=4156:D:\LANCE_SYSTEM_TOOLS\Tools\After_Tools\JetBrains\IntelliJIDEA2020.1.1\bin -Dfile.encoding=UTF-8 -classpath D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\charsets.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\deploy.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\access-bridge-64.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\cldrdata.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\dnsns.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\jaccess.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\jfxrt.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\localedata.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\nashorn.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\sunec.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\sunjce_provider.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\sunmscapi.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\sunpkcs11.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\ext\zipfs.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\javaws.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\jce.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\jfr.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\jfxswt.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\jsse.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\management-agent.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\plugin.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\resources.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Java\Java_1.8.0_131\jre\lib\rt.jar;E:\Java\IDEA\SpringCloud\cloud-gateway\target\classes;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-starter-gateway\2.2.3.RELEASE\spring-cloud-starter-gateway-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-starter\2.2.3.RELEASE\spring-cloud-starter-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-context\2.2.3.RELEASE\spring-cloud-context-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\security\spring-security-crypto\5.3.2.RELEASE\spring-security-crypto-5.3.2.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-commons\2.2.3.RELEASE\spring-cloud-commons-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\security\spring-security-rsa\1.0.9.RELEASE\spring-security-rsa-1.0.9.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\bouncycastle\bcpkix-jdk15on\1.64\bcpkix-jdk15on-1.64.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\bouncycastle\bcprov-jdk15on\1.64\bcprov-jdk15on-1.64.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-gateway-core\2.2.3.RELEASE\spring-cloud-gateway-core-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\boot\spring-boot-starter-validation\2.3.0.RELEASE\spring-boot-starter-validation-2.3.0.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\hibernate\validator\hibernate-validator\6.1.5.Final\hibernate-validator-6.1.5.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\jakarta\validation\jakarta.validation-api\2.0.2\jakarta.validation-api-2.0.2.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\projectreactor\addons\reactor-extra\3.3.3.RELEASE\reactor-extra-3.3.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\projectreactor\reactor-core\3.3.5.RELEASE\reactor-core-3.3.5.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\boot\spring-boot-starter-webflux\2.3.0.RELEASE\spring-boot-starter-webflux-2.3.0.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\boot\spring-boot-starter-json\2.3.0.RELEASE\spring-boot-starter-json-2.3.0.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.0\jackson-datatype-jdk8-2.11.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.0\jackson-datatype-jsr310-2.11.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.0\jackson-module-parameter-names-2.11.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\boot\spring-boot-starter-reactor-netty\2.3.0.RELEASE\spring-boot-starter-reactor-netty-2.3.0.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\projectreactor\netty\reactor-netty\0.9.7.RELEASE\reactor-netty-0.9.7.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-codec-http\4.1.49.Final\netty-codec-http-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-common\4.1.49.Final\netty-common-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-buffer\4.1.49.Final\netty-buffer-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-transport\4.1.49.Final\netty-transport-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-codec\4.1.49.Final\netty-codec-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-codec-http2\4.1.49.Final\netty-codec-http2-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-handler\4.1.49.Final\netty-handler-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-resolver\4.1.49.Final\netty-resolver-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-handler-proxy\4.1.49.Final\netty-handler-proxy-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-codec-socks\4.1.49.Final\netty-codec-socks-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-transport-native-epoll\4.1.49.Final\netty-transport-native-epoll-4.1.49.Final-linux-x86_64.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\netty\netty-transport-native-unix-common\4.1.49.Final\netty-transport-native-unix-common-4.1.49.Final.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\spring-web\5.2.6.RELEASE\spring-web-5.2.6.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\spring-beans\5.2.6.RELEASE\spring-beans-5.2.6.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\spring-webflux\5.2.6.RELEASE\spring-webflux-5.2.6.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\synchronoss\cloud\nio-multipart-parser\1.1.0\nio-multipart-parser-1.1.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\synchronoss\cloud\nio-stream-storage\1.1.3\nio-stream-storage-1.1.3.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-starter-netflix-eureka-client\2.2.3.RELEASE\spring-cloud-starter-netflix-eureka-client-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-netflix-hystrix\2.2.3.RELEASE\spring-cloud-netflix-hystrix-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\boot\spring-boot-autoconfigure\2.3.0.RELEASE\spring-boot-autoconfigure-2.3.0.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\boot\spring-boot-starter-aop\2.3.0.RELEASE\spring-boot-starter-aop-2.3.0.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\spring-aop\5.2.6.RELEASE\spring-aop-5.2.6.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\aspectj\aspectjweaver\1.9.5\aspectjweaver-1.9.5.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-netflix-eureka-client\2.2.3.RELEASE\spring-cloud-netflix-eureka-client-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\eureka\eureka-client\1.9.21\eureka-client-1.9.21.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\codehaus\jettison\jettison\1.3.7\jettison-1.3.7.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\netflix-commons\netflix-eventbus\0.3.0\netflix-eventbus-0.3.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\netflix-commons\netflix-infix\0.3.0\netflix-infix-0.3.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\commons-jxpath\commons-jxpath\1.3\commons-jxpath-1.3.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\joda-time\joda-time\2.3\joda-time-2.3.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\antlr\antlr-runtime\3.4\antlr-runtime-3.4.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\antlr\stringtemplate\3.2.1\stringtemplate-3.2.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\google\code\gson\gson\2.8.6\gson-2.8.6.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\apache\commons\commons-math\2.2\commons-math-2.2.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\archaius\archaius-core\0.7.6\archaius-core-0.7.6.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\google\guava\guava\29.0-android\guava-29.0-android.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\checkerframework\checker-compat-qual\2.5.5\checker-compat-qual-2.5.5.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\google\errorprone\error_prone_annotations\2.3.4\error_prone_annotations-2.3.4.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\google\j2objc\j2objc-annotations\1.3\j2objc-annotations-1.3.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\servo\servo-core\0.12.21\servo-core-0.12.21.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\apache\httpcomponents\httpclient\4.5.12\httpclient-4.5.12.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\apache\httpcomponents\httpcore\4.4.13\httpcore-4.4.13.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\commons-codec\commons-codec\1.14\commons-codec-1.14.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\commons-configuration\commons-configuration\1.10\commons-configuration-1.10.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\google\inject\guice\4.1.0\guice-4.1.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\javax\inject\javax.inject\1\javax.inject-1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\fasterxml\jackson\core\jackson-annotations\2.11.0\jackson-annotations-2.11.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\fasterxml\jackson\core\jackson-core\2.11.0\jackson-core-2.11.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\fasterxml\jackson\core\jackson-databind\2.11.0\jackson-databind-2.11.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-xml\2.11.0\jackson-dataformat-xml-2.11.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\fasterxml\jackson\module\jackson-module-jaxb-annotations\2.11.0\jackson-module-jaxb-annotations-2.11.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\codehaus\woodstox\stax2-api\4.2\stax2-api-4.2.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\fasterxml\woodstox\woodstox-core\5.3.0\woodstox-core-5.3.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\eureka\eureka-core\1.9.21\eureka-core-1.9.21.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-starter-netflix-archaius\2.2.3.RELEASE\spring-cloud-starter-netflix-archaius-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-netflix-ribbon\2.2.3.RELEASE\spring-cloud-netflix-ribbon-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-netflix-archaius\2.2.3.RELEASE\spring-cloud-netflix-archaius-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-starter-netflix-ribbon\2.2.3.RELEASE\spring-cloud-starter-netflix-ribbon-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\ribbon\ribbon\2.3.0\ribbon-2.3.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\ribbon\ribbon-transport\2.3.0\ribbon-transport-2.3.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\hystrix\hystrix-core\1.5.18\hystrix-core-1.5.18.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\ribbon\ribbon-core\2.3.0\ribbon-core-2.3.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\ribbon\ribbon-httpclient\2.3.0\ribbon-httpclient-2.3.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\netflix-commons\netflix-commons-util\0.3.0\netflix-commons-util-0.3.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\ribbon\ribbon-loadbalancer\2.3.0\ribbon-loadbalancer-2.3.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\io\reactivex\rxjava\1.3.8\rxjava-1.3.8.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-starter-loadbalancer\2.2.3.RELEASE\spring-cloud-starter-loadbalancer-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\cloud\spring-cloud-loadbalancer\2.2.3.RELEASE\spring-cloud-loadbalancer-2.2.3.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\boot\spring-boot-starter-cache\2.3.0.RELEASE\spring-boot-starter-cache-2.3.0.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\spring-context-support\5.2.6.RELEASE\spring-context-support-5.2.6.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\stoyanr\evictor\1.0.0\evictor-1.0.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\netflix\ribbon\ribbon-eureka\2.3.0\ribbon-eureka-2.3.0.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\com\thoughtworks\xstream\xstream\1.4.11.1\xstream-1.4.11.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\boot\spring-boot-starter\2.3.0.RELEASE\spring-boot-starter-2.3.0.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\boot\spring-boot\2.3.0.RELEASE\spring-boot-2.3.0.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\spring-context\5.2.6.RELEASE\spring-context-5.2.6.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\spring-expression\5.2.6.RELEASE\spring-expression-5.2.6.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\boot\spring-boot-starter-logging\2.3.0.RELEASE\spring-boot-starter-logging-2.3.0.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\apache\logging\log4j\log4j-to-slf4j\2.13.2\log4j-to-slf4j-2.13.2.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\apache\logging\log4j\log4j-api\2.13.2\log4j-api-2.13.2.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\spring-core\5.2.6.RELEASE\spring-core-5.2.6.RELEASE.jar;D:\LANCE_SYSTEM_TOOLS\Configuration\Maven\repository\org\springframework\spring-jcl\5.2.6.RELEASE\spring-jcl-5.2.6.RELEASE.jar com.springboot.CloudGatewayApplication
2020-06-07 11:12:17.927 ERROR 14380 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Failed to load property source from 'file:/E:/Java/IDEA/SpringCloud/cloud-gateway/target/classes/application.yml' (classpath:/application.yml)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:554) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:499) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:469) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$7(ConfigFileApplicationListener.java:448) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_131]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$8(ConfigFileApplicationListener.java:448) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_131]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:445) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$0(ConfigFileApplicationListener.java:348) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.FilteredPropertySource.apply(FilteredPropertySource.java:54) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:336) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:226) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:210) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:200) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:188) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:80) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at com.springboot.CloudGatewayApplication.main(CloudGatewayApplication.java:15) [classes/:na]
Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing a block collection
in 'reader', line 7, column 9:
- id: CLOUD-PROVIDER-MOVIE # ...
^
expected <block end>, but found '?'
in 'reader', line 8, column 9:
uri: http://localhost:9000 # 配 ...
^
at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockSequenceEntry.produce(ParserImpl.java:516) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeSequenceNode(Composer.java:208) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:257) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:248) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:236) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:162) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:257) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:248) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:236) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:162) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:257) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:248) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:236) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:162) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:257) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:248) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:236) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:162) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:95) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:134) ~[snakeyaml-1.26.jar:na]
at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:494) ~[snakeyaml-1.26.jar:na]
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:160) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:134) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.boot.env.OriginTrackedYamlLoader.load(OriginTrackedYamlLoader.java:75) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:50) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:608) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:524) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
... 25 common frames omitted
Process finished with exit code 1
solution :
- check whether the node directory level in the yml configuration file checks
against its
java.lang.UnsupportedOperationException resolvent
in the project List for operating times wrong Java. Lang. UnsupportedOperationException, later found operating List is composed of array transformation, by looking at the source code found problems, and write the test procedure is as follows.
code block:
public class ListTest {
public static void main(String[] args) {
String[] array = {"1","2","3","4","5"};
List<String> list = Arrays.asList(array);
list.add("6");
}
}
execution result:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:148)
at java.util.AbstractList.add(AbstractList.java:108)
at com.atguigu.test.ListTest.main(ListTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
The problem with
is the following: the add and remove methods in the List generated by the
call on arrays.aslist () are exception because ArrayList of the inner class of arrays.aslist () is returned instead of java.util.ArrayList. Arrays of inner class ArrayList and Java. Util. ArrayList are inherited AbstractList, remove, add method is the default in AbstractList throw UnsupportedOperationException and don’t make any operation. Java.util.ArrayList overrides these methods, but the ArrayList of Arrays internal class does not, so it will throw an exception. The solution:
public class ListTest {
public static void main(String[] args) {
String[] array = {"1","2","3","4","5"};
List<String> list = Arrays.asList(array);
List arrList = new ArrayList(list);
arrList.add("6");
}
}
div>
In Java, int is converted to string, and zero is added before the number of bits is insufficient
reproduced from: http://ych0108.iteye.com/blog/2174134 p>
Java int String number is not enough to fill in the front zero
String.format("%010d", 25); //25为int型
0 represents the character to be filled before
10 represents the length of the string
and d represents the argument of integer type
today I want to put an int to String not enough digits in front of the zero, in the original to see if there is a ready-made API, the results found most of the following
public static String addZeroForNum(String str,int strLength) {
int strLen =str.length();
if (strLen <strLength) {
while (strLen< strLength) {
StringBuffersb = new StringBuffer();
sb.append("0").append(str);//左补0
// sb.append(str).append("0");//右补0
str= sb.toString();
strLen= str.length();
}
}
return str;
}
but I think it’s a little bit of a hassle, so I thought of a slightly easier way to do it, the following line would be
String str = String.format("%5d", num).replace(" ", "0");
, where num is an int and STR is the converted result. That’s easy.
So,
, and I recently did a search on string.format, which actually comes with its own way to fill in the zero,
String.format("%06",12);//其中0表示补零而不是补空格,6表示至少6位
div>
Java uses regular expressions to intercept the contents between specified strings
package com.accord.util;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 正则表达式匹配两个字符串之间的内容
* @author Administrator
*
*/
public class RegexUtil {
public static void main(String[] args) {
String str = "<?xml version='1.0' encoding='UTF-8'?><ufinterface billtype='gl' filename='e:\1.xml' isexchange='Y' proc='add' receiver='1060337@1060337-003' replace='Y' roottag='sendresult' sender='01' successful='Y'><sendresult><billpk></billpk><bdocid>w764</bdocid><filename>e:\1.xml</filename><resultcode>1</resultcode><resultdescription>单据w764开始处理...单据w764处理完毕!</resultdescription><content>2017.09-记账凭证-1</content></sendresult><sendresult><billpk></billpk><bdocid>w1007</bdocid><filename>e:\1.xml</filename><resultcode>1</resultcode><resultdescription>单据w1007开始处理...单据w1007处理完毕!</resultdescription><content>2017.10-记账凭证-1</content></sendresult><sendresult><billpk></billpk><bdocid>w516</bdocid><filename>e:\1.xml</filename><resultcode>1</resultcode><resultdescription>单据w516开始处理...单据w516处理完毕!</resultdescription><content>2017.07-记账凭证-50</content></sendresult></ufinterface>";
//String str = "abc3443abcfgjhgabcgfjabc";
String rgex = "<bdocid>(.*?)</bdocid>";
System.out.println((new RegexUtil()).getSubUtil(str,rgex));
List<String> lists = (new RegexUtil()).getSubUtil(str,rgex);
for (String string : lists) {
System.out.println(string);
}
System.out.println((new RegexUtil()).getSubUtilSimple(str, rgex));
}
/**
* 正则表达式匹配两个指定字符串中间的内容
* @param soap
* @return
*/
public List<String> getSubUtil(String soap,String rgex){
List<String> list = new ArrayList<String>();
Pattern pattern = Pattern.compile(rgex);// 匹配的模式
Matcher m = pattern.matcher(soap);
while (m.find()) {
int i = 1;
list.add(m.group(i));
i++;
}
return list;
}
/**
* 返回单个字符串,若匹配到多个的话就返回第一个,方法与getSubUtil一样
* @param soap
* @param rgex
* @return
*/
public String getSubUtilSimple(String soap,String rgex){
Pattern pattern = Pattern.compile(rgex);// 匹配的模式
Matcher m = pattern.matcher(soap);
while(m.find()){
return m.group(1);
}
return "";
}
}
operation results:
[w764, w1007, w516]
w764
w1007
w516
w764
Compare whether two sets are the same in Java
in Java API, it seems that there is no way to compare the contents of two sets, so we can only write one by ourselves to realize it. In fact, it is relatively simple to compare the number of records to see whether they are the same, and then see whether the contents are consistent. The test method is as follows:
public static boolean equals(Set<?> set1, Set<?> set2){
if(set1 == null || set2 ==null){//null就直接不比了
return false;
}
if(set1.size()!=set2.size()){//大小不同也不用比了
return false;
}
return set1.containsAll(set2);//最后比containsAll
}
unit test:
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class TestSetUtils {
@Test
public void test1() {
Set<String> test1 = new HashSet<>();
test1.add("a");
test1.add("b");
Set<String> test2 = new HashSet<>();
test2.add("b");
test2.add("c");
assertThat(SetUtils.equals(test1, test2), is(false));
}
@Test
public void test2() {
Set<String> test1 = new HashSet<>();
test1.add("a");
test1.add("b");
Set<String> test2 = new HashSet<>();
test2.add("a");
test2.add("b");
test2.add("c");
assertThat(SetUtils.equals(test1, test2), is(false));
}
@Test
public void test3() {
Set<String> test1 = new HashSet<>();
test1.add("a");
test1.add("b");
test1.add("c");
Set<String> test2 = new HashSet<>();
test2.add("a");
test2.add("b");
assertThat(SetUtils.equals(test1, test2), is(false));
}
//set ignore sequence
@Test
public void test4() {
Set<String> test1 = new HashSet<>();
test1.add("a");
test1.add("b");
Set<String> test2 = new HashSet<>();
test2.add("b");
test2.add("a");
assertThat(SetUtils.equals(test1, test2), is(true));
}
@Test
public void test5() {
Set<String> test1 = new HashSet<>();
test1.add("a");
Set<String> test2 = new HashSet<>();
test2.add("a");
assertThat(SetUtils.equals(test1, test2), is(true));
}
}
p>
reproduced from: http://ju.outofmemory.cn/entry/288737 p>
How many pieces of data can list store in Java?
from the perspective of language, java.util.List is an interface, under which there are multiple N implementations, the most commonly used are ArrayList and LinkedList and its various inheritance or synchronization implementation (such as Vector/Queue/Stack)
ArrayList inside is to take the array storage, then the upper limit is Integer.MAX_VALUE
LinkedList inside is a LinkedList, theoretically infinite
also, everything in the List is in memory (although you can implement one yourself), so how much you can put depends on the size and type of stuff you’re putting. The
size aspect is easy to calculate, if one object is 1K, then 400,000 will take up at least 400M memory (not counting other usage).
virtual machine memory classification, if it is a common object, generally use the Heap space, if it is a constant or something like string.intern (), then use the Permanent Generation.
in actual development, the default memory size of virtual machine varies according to different virtual machine implementations. The maximum heap size can be adjusted with -xmx when the application is launched, such as adjusting the maximum heap size to 2G:
java -Xmx2048m cn.gefostudio.App
adjust the maximum size of the immortal band to 1G:
java -XX:MaxPermSize=1024m cn.gefostudio.App
Java operation temporary file creation and deletion
in Java’s File class, there is a createTempFile(String prefix,String suffix) that is called to create a temporary File in the system’s default temporary File directory.
prefix means filename.
suffix represents the suffix of a file, in the form “. TMP “, note that “. “
is needed
final File htmlFile = File.createTempFile("temp", ".html");//创建临时文件
logger.info("临时文件所在的本地路径:" + htmlFile.getCanonicalPath());
FileOutputStream fos = new FileOutputStream(htmlFile);
try {
//这里处理业务逻辑
} finally {
//关闭临时文件
fos.flush();
fos.close();
htmlFile.deleteOnExit();//程序退出时删除临时文件
}
on win7, the default directory for temporary files is C:\Users\Administrator\AppData\Local\Temp. After
finishes using the temporary file, executing htmlfile.deleteonexit () will automatically delete the temporary file.
Why do we not need to write implementation classes in mybatis to get the objects we need
let’s say we need now we need a method
is all the information in the query table
we’ll write
@Override
public List<User> selectAll() {
SqlSession sqlSession = factory.openSession();
List<User> userList = sqlSession.selectList("com.tubai.dao.UserDao.selectAll");
sqlSession.close();
return userList;
}
is mainly through the sqlSession selectList to achieve the function
so how does Mybatis do this work for us?
pursue source
let’s start
in debug mode and step into
when this sentence is executed
userDao = sqlSession.getMapper(UserDao.class);
to p>
public <T> T getMapper(Class<T> type) {
return this.configuration.getMapper(type, this);
}
next->
public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
return this.mapperRegistry.getMapper(type, sqlSession);
}
->
public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
MapperProxyFactory<T> mapperProxyFactory = (MapperProxyFactory)this.knownMappers.get(type);
if (mapperProxyFactory == null) {
throw new BindingException("Type " + type + " is not known to the MapperRegistry.");
} else {
try {
return mapperProxyFactory.newInstance(sqlSession);
} catch (Exception var5) {
throw new BindingException("Error getting mapper instance. Cause: " + var5, var5);
}
}
}
we found that
was executed
return mapperProxyFactory.newInstance(sqlSession);
continue into ->
public T newInstance(SqlSession sqlSession) {
MapperProxy<T> mapperProxy = new MapperProxy(sqlSession, this.mapperInterface, this.methodCache);
return this.newInstance(mapperProxy);
}
->
protected T newInstance(MapperProxy<T> mapperProxy) {
return Proxy.newProxyInstance(this.mapperInterface.getClassLoader(), new Class[]{this.mapperInterface}, mapperProxy);
}
here we find that the newProxyInstance method that calls the dynamic proxy
so let’s go straight to the third parameter
open the class MapperProxy
find the invoke method inside
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
if (Object.class.equals(method.getDeclaringClass())) {
return method.invoke(this, args);
}
if (this.isDefaultMethod(method)) {
return this.invokeDefaultMethod(proxy, method, args);
}
} catch (Throwable var5) {
throw ExceptionUtil.unwrapThrowable(var5);
}
MapperMethod mapperMethod = this.cachedMapperMethod(method);
return mapperMethod.execute(this.sqlSession, args);
}
finds that it finally calls
mapperMethod.execute(this.sqlSession, args);
open the source code for this method and continue
public Object execute(SqlSession sqlSession, Object[] args) {
Object param;
Object result;
switch(this.command.getType()) {
case INSERT:
param = this.method.convertArgsToSqlCommandParam(args);
result = this.rowCountResult(sqlSession.insert(this.command.getName(), param));
break;
case UPDATE:
param = this.method.convertArgsToSqlCommandParam(args);
result = this.rowCountResult(sqlSession.update(this.command.getName(), param));
break;
case DELETE:
param = this.method.convertArgsToSqlCommandParam(args);
result = this.rowCountResult(sqlSession.delete(this.command.getName(), param));
break;
case SELECT:
if (this.method.returnsVoid() && this.method.hasResultHandler()) {
this.executeWithResultHandler(sqlSession, args);
result = null;
} else if (this.method.returnsMany()) {
result = this.executeForMany(sqlSession, args);
} else if (this.method.returnsMap()) {
result = this.executeForMap(sqlSession, args);
} else if (this.method.returnsCursor()) {
result = this.executeForCursor(sqlSession, args);
} else {
param = this.method.convertArgsToSqlCommandParam(args);
result = sqlSession.selectOne(this.command.getName(), param);
}
break;
case FLUSH:
result = sqlSession.flushStatements();
break;
default:
throw new BindingException("Unknown execution method for: " + this.command.getName());
}
if (result == null && this.method.getReturnType().isPrimitive() && !this.method.returnsVoid()) {
throw new BindingException("Mapper method '" + this.command.getName() + " attempted to return null from a method with a primitive return type (" + this.method.getReturnType() + ").");
} else {
return result;
}
}
in Case:SELECT we find
result = this.executeForMany(sqlSession, args);
let’s do
private <E> Object executeForMany(SqlSession sqlSession, Object[] args) {
Object param = this.method.convertArgsToSqlCommandParam(args);
List result;
if (this.method.hasRowBounds()) {
RowBounds rowBounds = this.method.extractRowBounds(args);
result = sqlSession.selectList(this.command.getName(), param, rowBounds);
} else {
result = sqlSession.selectList(this.command.getName(), param);
}
if (!this.method.getReturnType().isAssignableFrom(result.getClass())) {
return this.method.getReturnType().isArray() ? this.convertToArray(result) : this.convertToDeclaredCollection(sqlSession.getConfiguration(), result);
} else {
return result;
}
}~
and finally we found
sqlSession.selectList
div>
Mybatis uses step-by-step lazy loading to cause abnormal JSON conversion. The interface 500 reports an error
Mybatis USES lazy step loading to cause json conversion exception
-
anomaly description strong>
No serializer found for class org. Apache. Ibatis. Executor. Loader. The javassist. JavassistProxyFactory... code>
p> li> -
solve abnormal strong> * * * p>
in distributed query each related bean class strong> add annotation
@ JsonIgnoreProperties (value = {} "handler") code> p> li> -
reason
lazy loading is you have to use data will give you query 0, but 1 directly query object 2 into json string will lead to 3 results have not been query out of json4, This is what causes the interface 500 exception. Note : object does not load SQL query, only when output this object is use this data 0 will be 1 query 2 from the database and assign data to dependent object
3
4
5