Category Archives: JAVA

[Solved] Maven project startup error {datasource-1} init error

Problem: the project downloaded from SVN reports an error: {datasource-1} init error} oracle jdbc. OracleDriver

Reason: in the POM corresponding to the project The configuration corresponding to orcal database connection is not introduced in the XML file

<dependency>
          <groupId>com.oracle</groupId>
          <artifactId>ojdbc6</artifactId>
          <version>11.2.0.4.0</version>
        </dependency>

After adding configuration, restart the project and solve the problem

[Solved] Springboot Error: Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.

Error Messages:

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2020-09-17 16:34:52.056 ERROR 19128 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
The bean ‘dataSource’, defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationHikari.class],could not beregistered. A bean with that name hasal ready been defined in classpath resource[org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationHikari.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationHikari.class],could not beregistered. A bean with that name hasal ready been defined in classpath resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationHikari.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
Disconnected from the target VM, address: ‘127.0.0.1:62029’, transport: ‘socket’
Process finished with exit code 1

————————————————

From the error message, we can see that the bean dataSource has been registered.

Solution:
Add the following configuration to the configuration file

# When set to true, a later defined bean will override a previously defined bean with the same name
spring.main.allow-bean-definition-overriding=true

#Note: The default in spring is true, which means that overriding of beans with the same name is supported by default. The default value in springboot is false, which means that beans with the same name are not supported to be overridden.

Root cause analysis

After all, it was found that the problem was caused by the version matching between springboot and springcloud; After the version is lowered, the problem is solved naturally. This is the recommended solution, which is fundamentally solved.

[Solved] IDEA Package Spring Boot Project Error: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project randomaward: Input length = 1 -> [Help 1]

Error in idea packaging spring boot project: failed to execute goal org.apache.maven.plugins: Maven resources plugin: 3.2.0: resources (default resources) on project random Watch: input length = 1 – & gt; [Help 1]

I encountered such a problem when packaging the project today.

[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project randomaward: Input length = 1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Solution:

1. Confirm whether it is in UTF-8 format

2. After changing UTF-8, application.yml will change

The following errors may be reported when starting the project:

org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1

Cause of problem:

The application.yml file is incorrectly written. Generally, the reason is that there are many or few spaces. Check the spaces
the code of application.yml has changed, and the problems of GBK and UTF-8 coding formats
solution:
the fastest and most effective way is to copy everything on application.yml, delete the current application.yml file, and create a new application.yml, Paste it
note: no matter whether an error is reported or not, it is best to delete application.yml and rebuild it again (it is valid for personal trial).

3. Skip test mode

4. Start packing

Successful as shown in the figure:

Here, the jar is packaged!

[Solved] ava.io.IOException: HADOOP_HOME or hadoop.home.dir are not set

ava.io.IOException: HADOOP_HOME or hadoop.home.dir are not set.

at org.apache.hadoop.util.Shell.checkHadoopHome(Shell.java:302)
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:327)
at org.apache.hadoop.util.GenericOptionsParser.preProcessForWindows(GenericOptionsParser.java:438)
at org.apache.hadoop.util.GenericOptionsParser.parseGeneralOptions(GenericOptionsParser.java:484)
at org.apache.hadoop.util.GenericOptionsParser.<init>(GenericOptionsParser.java:170)
at org.apache.hadoop.util.GenericOptionsParser.<init>(GenericOptionsParser.java:153)
at WordCount.main(WordCount.java:52)
ERROR - Failed to locate the winutils binary in the hadoop binary path
 java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries

Solution: add the following code in the first line inside the main method in application.java

System.setProperty(“hadoop.home.dir”, “D:\\Develop\\hadoop-2.6.0”);

[Solved] Springboot integrate swagger Error: failed to start bean ‘documentationpluginsboot

First, paste my jar package version

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/>
    </parent>


 <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>25.1-jre</version>
        </dependency>

Some people failed to start the bean ‘documentationpluginsboot’ because the guava version is too low. The online strategy is also to modify the guava version

Finally, it is found that the springboot version is too high and incompatible. Just change the springboot version to 2.2.5

[Solved] EL1004E: Method call: Method fmtdate(java.util.Date,java.lang.String) cannot be found on org.thymele

When using springboot to integrate with thymeleaf, it is found that the time field localdatetime in java8 will report an error when using dates.format in the foreground.

<tr>
   <td>Spike start time</td>
   <td th:text="${#dates.format(goods.startDate, 'yyyy-MM-dd HH:mm:ss')}"></td>
</tr>

Error message:

org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method format(java.time.LocalDateTime,java.lang.String) cannot be found on type org.thymeleaf.expression.Dates
    at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:226) ~[spring-expression-5.3.12.jar:5.3.12]
    at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:135) ~[spring-expression-5.3.12.jar:5.3.12]
    at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:55) ~[spring-expression-5.3.12.jar:5.3.12]
    at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:387) ~[spring-expression-5.3.12.jar:5.3.12]
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:92) ~[spring-expression-5.3.12.jar:5.3.12]
    at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:112) ~[spring-expression-5.3.12.jar:5.3.12]
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:337) ~[spring-expression-5.3.12.jar:5.3.12]
    at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:265) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:166) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.standard.expression.Expression.execute(Expression.java:109) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.standard.processor.AbstractStandardExpressionAttributeTagProcessor.doProcess(AbstractStandardExpressionAttributeTagProcessor.java:144) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleOpenElementEnd(TemplateHandlerAdapterMarkupHandler.java:304) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
    at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleOpenElementEnd(InlinedOutputExpressionMarkupHandler.java:278) ~[thymeleaf-3.0.12.RELEASE.jar:3.0

Solution:

After searching relevant data, it is found that thymeleaf has added an enhancement package for such error reports. In Maven project, the following packages need to be introduced into POM:

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>

Then change the code in thymeleaf as follows:

<tr>
    <td>Spike start time</td>
    <td th:text="${#temporals.format(goods.startDate,'yyyy-MM-dd HH:mm:ss')}"></td>
</tr>

[Solved] Docker Run ElasticSearch Error: docker: invalid reference format: repository name must be lowercase.

Problems encountered

When starting the elasticsearch container with docker, enter

docker run --name elasticsearch -p 9200:9200 -p 9300:9300\
-e "discovery.type=single-node"\
-e ES_JAVA_OPTS="-Xms64m -Xmx128m"\
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml\
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data\
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins\
-d elasticsearch:7.6.2

report errors

docker: invalid reference format: repository name must be lowercase.

reason:

Docker: invalid reference format: repository name must be lowercase.

There is no space before \ in the shell

Solution:

Add a space before all \, and after modification, it is as follows:

docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" \
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.6.2

Run successfully