Tag Archives: java

Springboot error, unable to read configuration file: could not resolve placeholder ‘xxx’ in value “${XXX}

Just configure the following code on the startup class

@Bean
    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {

        PropertySourcesPlaceholderConfigurer placeholderConfigurer = new PropertySourcesPlaceholderConfigurer();

        placeholderConfigurer.setIgnoreUnresolvablePlaceholders(true);

        return placeholderConfigurer;
    }

should be OK

Spring boot prompt could not resolve placeholder in string value

1. Problem description

 

Spring boot refers to the configuration in YML in entity class

    @Value("${shiro.session.expireTime}")
    private final int expireTime = 30;

As soon as the project is started, an error is reported, indicating that could not resolve placeholder in string value. This error is basically caused by “configuration file not found”( application.yml )】

 

2. Solutions

 

Check whether the target / classes directory exists application.yml configuration file

If it exists, add the primary key of propertysource to the configuration class, and judge whether it exists according to the error log application.yml Configuration file.

@Configuration
@PropertySource("classpath:application.yml")
public class ShiroConfig {

 

appear java.lang.NoClassDefFoundError A kind of reason and solution of the mistake

Today, when running a java program, I met java.lang.NoClassDefFoundError My mistake. At first glance, it’s the classpath setting. It turns out that the solution is also very simple. There are two ways:

When running, with the – CP parameter, the value is “‘”, which indicates the current directory. For example:

java -cp . VolcanoRobot

Write classpath =. \;% Java in the environment variable_ HOME%\lib\ tools.jar Again, pay attention to the one in front. You can:

java VolcanoRobot

In comparison, the latter method is more thorough.

Solve the problem of unable to start under zookeeper Linux

When installing zookeeper under Linux, the following error occurs:

[ [email protected] bin]$ ./ zkServer.sh start

JMX disabled by user request

Using config: /opt/zookeeper-3.3.3/bin/../conf/ zoo.cfg

Starting zookeeper …

STARTED

[ [email protected] bin]$ 2011-07-05 10:33:57,587 – INFO [ main:QuorumPeerCon[email protected] ] – Reading configuration from: /opt/zookeeper-3.3.3/bin/../conf/ zoo.cfg

2011-07-05 10:33:57,596 – WARN [ main:[email protected] ] – Either no config or no quorum defined in config, running in standalone mode

Exception in thread “main” java.lang.NoSuchMethodError : method java.lang.management . ManagementFactory.getPlatformMBeanServer with signature () Ljavax.management.MBeanServer ; was not found.

at org.apache.zookeeper . jmx.ManagedUtil.registerLog4jMBeans ( ManagedUtil.java:48 )

at org.apache.zookeeper . server.ZooKeeperServerMain.initializeAndRun ( ZooKeeperServerMain.java:73 )

at org.apache.zookeeper . server.ZooKeeperServerMain.main ( ZooKeeperServerMain.java:51 )

at org.apache.zookeeper . server.quorum.QuorumPeerMain .initializeAndRun( QuorumPeerMain.java:108 )

at org.apache.zookeeper . server.quorum.QuorumPeerMain .main( QuorumPeerMain.java:76 )

Found, not found java.lang.management The next way. If you are using the standard JDK, such an error should not occur. So check it out zkServer.sh Script. It is found that the script to start the Java program is as follows:

Bash code

java “- Dzookeeper.log.dir= ${ZOO_ LOG_ DIR}” “- Dzookeeper.root.logger= ${ZOO_ LOG4J_ PROP}” \

-cp “$CLASSPATH” $JVMFLAGS $ZOOMAIN “$ZOOCFG” &

Executing Java command directly under Linux, the output is as follows:

Bash code

[ [email protected] bin]$ java

Usage: gij [OPTION] … CLASS [ARGS] …

to invoke CLASS.main , or

gij -jar [OPTION] … JARFILE [ARGS] …

to execute a jar file

Try `gij –help’ for more information.

Obviously, zkServer.sh Incorrect java used. Use the Java of Gij. To solve this problem, simply change the script to:

Bash code

$JAVA_ HOME/bin/java “- Dzookeeper.log.dir= ${ZOO_ LOG_ DIR}” “- Dzookeeper.root.logger= ${ZOO_ LOG4J_ PROP}” \

-cp “$CLASSPATH” $JVMFLAGS $ZOOMAIN “$ZOOCFG” &

After this modification, it can run normally.

It is mainly to replace the system’s own Java path, so that he can identify his own installed Java (it’s better to delete the system’s own JDK before installing software)

@Value sets the default value

When using @ value annotation to automatically inject variables, a common problem is that we may forget to set the parameter in the configuration parameter, resulting in an error in the whole project. In fact, we can set a default value when injecting the @ value annotated variable. If the configuration parameter is not found, it is equivalent to a way to get the bottom of the story Case No

Usage without default value:

@Value("${spring.port}")
private String port;

To increase the default value:

@Value("${spring.port:8080}")
private String port;

Here we need to pay attention to:

Even if the value of your configuration parameter is string type, you don’t need to add double quotation marks. Static modified variables will fail to be injected through @ value

If it is necessary to set the value of @ value to the static variable due to specific requirements, the following method can be used

Use @ value to set the value of static variable

public static String port;

@Value("${spring.port:8080}")
public void setPort(String port){
	Class.port = port;
}

Analysis of JDBC connection to MySQL

JDBC connection to MySQL problem resolution
Recently, a series of problems occurred while configuring JDBC to connect to MySQL. Fortunately, it all worked out in the end. Here is a summary of the problems, hoping to help others with the same problems.
BlueStragglers shares the joy of technology growth

directory
A JDBC connection to MySQL analytical error: com.mysql.jdbc.exceptions.jdbc4.Com municationsException: Communications link failure2. Unknown initial character set index ‘255’ received from server.Initial client character3. Error: references to the entity ‘characterEncoding’ must begin with ‘; ‘End of delimiter 4. Reference content

1. An error: com.mysql.jdbc.exceptions.jdbc4.Com municationsException: Communications link failure
This problem is most likely due to a problem with the mysql-connector-java version of the pom.xml file. I started with version 5.1.44 and found that I kept reporting this error. This issue can be resolved by returning 5.1.6.
Of course, there is another case where this error is reported: MySQL Server will automatically disconnect and report an error if the connection takes more than 8 hours. The solution is usually to modify the configuration file.
Unknown initial character set index ‘255’ received from server.Initial client character
This problem is generally caused by the occurrence of Chinese in MySQL, which can not be properly resolved. The solution is to put a UTF8 encoding requirement at the end of the URL to avoid errors. For example, the source statement is:

<property name="url" value="jdbc:mysql://10.201.0.27:3307/mybatis"/>

This can be modified to the following statement:

<property name="url" value="jdbc:mysql://10.201.0.27:3307/mybatis?useUnicode=true&amp;characterEncoding=utf8"/>

3. Error: references to the entity ‘CharacterEncoding’ must begin with ‘; ‘End of the delimiter
Encounter this problem, I am quite surprised, actually is Chinese report error. It was later discovered that MySQL had a problem with characterEncoding= UTF8, so it may have been for this reason that the error was reported in Chinese.
& & instead. For example, the following statement:

<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&characterEncoding=utf8" />

The above statement will report an error. If you need to modify it to the following statement, it will not report an error:

<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&amp;characterEncoding=utf8" />

4. References

    JDBC connection to MySQL references to the entity 'CharacterEncoding' must begin with '; 'End of delimiter

How to solve the problem of “version 11 or greater is required” in eclipse 2020

After I installed Eclipse 2020, I opened it directly and said “Version 11 or greater is required”, so I installed JDK11 following its instructions, but I still reported the same error after I installed Eclipse 2020. After searching on the Internet, I found that this should be the solution:
Find the eclipse in the file directory. The ini file:

at the beginning of the ini file to add this two lines:

the first line – vm, the second line of the JDK package javaw. Exe open path. Save it and you’ll be able to open Eclipse 2020 normally.

The reason why HashMap multithreads send out life and death loops

This article is a learning record of Vaccine: Java HashMap’s endless loop, welcome to discuss ~
Suppose the state of a cylinder to be expanded is as follows:
1->; 2-> Null
1 for the current thread to insert a new element of an array of e: 1 and the next element next:
when thread 2 completed the expansion, the pointer to the current status to 2 – & gt; 1-> NULL
Thread 1 continues:
rst (e:1,next:2)
n>arrel :1 ->; null

e=next=2;
next=e1.next=1;

> (e:2,next:1)
> 1-> null

e=next=1;
next=e1.next=null;

(e:1,next:null)
new barrel :1 ->; 2-> 1 is just 1 lt; -> 2

e=next=null;

cpu100%
7 using head insert, 1.8 using tail insert for capacity expansion.
1.7 using head insert, 1.8 using tail insert for capacity expansion.