Category Archives: JAVA

error cb() never called! error This is an error with npm itself

Various methods have been tried on the Internet, but they haven’t been solved. Finally, the latest version of nodejs is installed manually and normal (you can directly overwrite and install it to the original path)

Attached information:
gnvm is a simple node.js multi version manager under windows, similar to NVM nvmw nodist
https://github.com/Kenshin/gnvm

NPM replace with a different version

#npm install -g npm@version
npm install -g [email protected]

Nodejs comes with NPM

ZK Error contacting service. It is probably not running [How to Solve]

A bug was encountered while recording the test

After initiating the request, return to 502 bad gateway (nginx/1.1.19) to check that nginx starts normally. After checking the back-end log, an error is found

java.net.ConnectException: Connection refused
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
	at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
	at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)

The error message shows that the Dubbo link and the zookeeper link are not available

Find the bin directory of zookeeper and use./zkserver.sh start to start normally
but when using./zkserver.sh status, an error is found in the error contacting service. It is probable not running

ZooKeeper JMX enabled by default
Using config: /opt/zk1/zookeeper-3.4.10/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.

Use the systemctl status ZK command to view the status (small gray dots)

● zk.service - Zookeeper Service
   Loaded: loaded (/etc/systemd/system/zk.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Mon 2021-10-11 20:17:54 CST; 2s ago
  Process: 9433 ExecStop=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh stop (code=exited, status=0/SUCCESS)
  Process: 9448 ExecStart=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh start (code=exited, status=0/SUCCESS)
 Main PID: 9458 (code=exited, status=1/FAILURE);         : 9485 (sleep)
    Tasks: 1
   Memory: 256.0K
      CPU: 3.695s
   CGroup: /system.slice/zk.service
           └─control
             └─9485 /bin/sleep 4
             
Oct 11 20:17:54 ubuntu systemd[1]: Starting Zookeeper Service...
Oct 11 20:17:54 ubuntu zkServer.sh[9448]: ZooKeeper JMX enabled by default
Oct 11 20:17:54 ubuntu zkServer.sh[9448]: Using config: /opt/zk1/zookeeper-3.4.10/bin/../conf/zoo.cfg
Oct 11 20:17:55 ubuntu zkServer.sh[9448]: Starting zookeeper ... STARTED
Oct 11 20:17:56 ubuntu systemd[1]: zk.service: Main process exited, code=exited, status=1/FAILURE

Attempt to start systemctl start ZK

Job for zk.service failed because the control process exited with error code. See "systemctl status zk.service" and "journalctl -xe" for details.

Check systemctl status ZK again

● zk.service - Zookeeper Service
   Loaded: loaded (/etc/systemd/system/zk.service; enabled; vendor preset: enabled)
   Active: activating (start-post) since Mon 2021-10-11 20:18:16 CST; 1s ago
  Process: 9894 ExecStop=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh stop (code=exited, status=0/SUCCESS)
  Process: 9910 ExecStart=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh start (code=exited, status=0/SUCCESS)
 Main PID: 9920 (java);         : 9953 (sleep)
    Tasks: 26
   Memory: 170.6M
      CPU: 3.268s
   CGroup: /system.slice/zk.service
           ├─9920 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,ROLLINGFILE -cp /opt/zk1/zookeeper-3.4.10/bin/../build/classes:/opt/zk1/zookeeper-3.4.10/bin/../build/lib/*.jar:/
           └─control
             └─9953 /bin/sleep 4

Oct 11 20:18:16 ubuntu systemd[1]: Starting Zookeeper Service...
Oct 11 20:18:16 ubuntu zkServer.sh[9910]: ZooKeeper JMX enabled by default
Oct 11 20:18:16 ubuntu zkServer.sh[9910]: Using config: /opt/zk1/zookeeper-3.4.10/bin/../conf/zoo.cfg
Oct 11 20:18:17 ubuntu zkServer.sh[9910]: Starting zookeeper ... STARTED

I still can’t find it
view the configuration file less zoo.cfg to find the log path

dataLogDir=/opt/zk1/zookeeper-3.4.10/datalog

Enter/opt/ZK1/zookeeper-3.4.10/datalog/version-2 and find a log suspected to be damaged (log. 220770)

-rw-r--r-- 1 root root 67108880 Sep 22 00:21 log.1ce8b6
-rw-r--r-- 1 root root 67108880 Sep 22 02:30 log.1e0dbe
-rw-r--r-- 1 root root 67108880 Sep 22 11:15 log.1e4a05
-rw-r--r-- 1 root root 67108880 Sep 22 20:26 log.1f407d
-rw-r--r-- 1 root root 67108880 Sep 23 02:30 log.20427c
-rw-r--r-- 1 root root 67108880 Sep 23 12:32 log.20ecc9
-rw-r--r-- 1 root root        0 Sep 23 12:33 log.220770

Delete this log RM log.220770 start again and check the status
systemctl start ZK systemctl status ZK (small green dot)

● zk.service - Zookeeper Service
   Loaded: loaded (/etc/systemd/system/zk.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2021-10-11 20:19:30 CST; 5s ago
  Process: 11032 ExecStop=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh stop (code=exited, status=0/SUCCESS)
  Process: 11088 ExecStartPost=/bin/sleep 4 (code=exited, status=0/SUCCESS)
  Process: 11047 ExecStart=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh start (code=exited, status=0/SUCCESS)
 Main PID: 11057 (java)
    Tasks: 28
   Memory: 222.5M
      CPU: 4.229s
   CGroup: /system.slice/zk.service
           └─11057 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,ROLLINGFILE -cp /opt/zk1/zookeeper-3.4.10/bin/../build/classes:/opt/zk1/zookeeper-3.4.10/bin/../build/lib/*.jar:

Oct 11 20:19:25 ubuntu systemd[1]: Starting Zookeeper Service...
Oct 11 20:19:25 ubuntu zkServer.sh[11047]: ZooKeeper JMX enabled by default
Oct 11 20:19:25 ubuntu zkServer.sh[11047]: Using config: /opt/zk1/zookeeper-3.4.10/bin/../conf/zoo.cfg
Oct 11 20:19:26 ubuntu zkServer.sh[11047]: Starting zookeeper ... STARTED
Oct 11 20:19:30 ubuntu systemd[1]: Started Zookeeper Service.

Restart the back-end service. The error is found and solved
in addition, there are other situations that can lead to this problem
1. The firewall is not closed
Ubuntu
CentOS
2. The port is occupied
netstat – ANP | grep port number
kill – 9 ID

Jmeter Error: ERROR o.a.j.JMeter: Uncaught exception in thread Thread[AWT-EventQueue-0,6,main]

Recently, I started to learn JMeter by myself, but I found an error when running the interface (the interface has passed the postman, and finally found the reason after self-examination)

First, the error prompt: we mainly look at error. We can see error o.a.j.jmeter: uncaught exception in thread thread [awt-eventqueue-0,6, main], and then look down to see relevant fields such as darkfilexxx. It can be solved by changing the dark skin directly, as shown in the figure below:

2021-10-13 20:27:42,010 INFO o.j.r.PluginManager: Plugins Status: [jpgc-plugins-manager=1.6, jmeter-core=5.4.1, jmeter-ftp=5.4.1, jmeter-http=5.4.1, jmeter-jdbc=5.4.1, jmeter-jms=5.4.1, jmeter-junit=5.4.1, jmeter-java=5.4.1, jmeter-ldap=5.4.1, jmeter-mail=5.4.1, jmeter-mongodb=5.4.1, jmeter-native=5.4.1, jmeter-tcp=5.4.1, jmeter-components=5.4.1]
2021-10-13 20:27:54,241 INFO o.a.j.s.FileServer: Default base='/Users/kidd'
2021-10-13 20:27:54,243 INFO o.a.j.g.a.Load: Loading file: /Users/kidd/jmetertesting_file/View Results Tree.jmx
2021-10-13 20:27:54,244 INFO o.a.j.s.FileServer: Set new base='/Users/kidd/jmetertesting_file'
2021-10-13 20:27:54,383 INFO o.a.j.s.SaveService: Testplan (JMX) version: 2.2. Testlog (JTL) version: 2.2
2021-10-13 20:27:54,391 INFO o.a.j.s.SaveService: Using SaveService properties version 5.0
2021-10-13 20:27:54,392 INFO o.a.j.s.SaveService: Using SaveService properties file encoding UTF-8
2021-10-13 20:27:54,394 INFO o.a.j.s.SaveService: Loading file: /Users/kidd/jmetertesting_file/View Results Tree.jmx
2021-10-13 20:27:54,511 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/html is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
2021-10-13 20:27:54,511 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for application/xhtml+xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
2021-10-13 20:27:54,511 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for application/xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
2021-10-13 20:27:54,511 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
2021-10-13 20:27:54,511 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/vnd.wap.wml is org.apache.jmeter.protocol.http.parser.RegexpHTMLParser
2021-10-13 20:27:54,511 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/css is org.apache.jmeter.protocol.http.parser.CssParser
2021-10-13 20:27:54,640 INFO o.a.j.s.SampleResult: Note: Sample TimeStamps are START times
2021-10-13 20:27:54,640 INFO o.a.j.s.SampleResult: sampleresult.default.encoding is set to ISO-8859-1
2021-10-13 20:27:54,641 INFO o.a.j.s.SampleResult: sampleresult.useNanoTime=true
2021-10-13 20:27:54,641 INFO o.a.j.s.SampleResult: sampleresult.nanoThreadSleep=5000
2021-10-13 20:27:54,763 INFO o.a.j.v.ViewResultsFullVisualizer: Add JavaFX to your Java installation if you want to use renderer: org.apache.jmeter.visualizers.RenderInBrowser
2021-10-13 20:27:54,844 INFO o.a.j.s.FileServer: Set new base='/Users/kidd/jmetertesting_file'
2021-10-13 20:27:54,894 ERROR o.a.j.JMeter: Uncaught exception in thread Thread[AWT-EventQueue-0,6,main]
java.lang.IllegalAccessError: class com.github.weisj.darklaf.ui.filechooser.DarkFilePaneUIBridge$DetailsTableModel (in unnamed module @0x4c40b76e) cannot access class sun.awt.shell.ShellFolder (in module java.desktop) because module java.desktop does not export sun.awt.shell to unnamed module @0x4c40b76e
	at com.github.weisj.darklaf.ui.filechooser.DarkFilePaneUIBridge$DetailsTableModel.updateColumnInfo(DarkFilePaneUIBridge.java:1128) ~[darklaf-core-2.5.4.jar:2.5.4]
	at com.github.weisj.darklaf.ui.filechooser.DarkFilePaneUIBridge$DetailsTableModel.<init>(DarkFilePaneUIBridge.java:1115) ~[darklaf-core-2.5.4.jar:2.5.4]
	at com.github.weisj.darklaf.ui.filechooser.DarkFilePaneUIBridge.getDetailsTableModel(DarkFilePaneUIBridge.java:576) ~[darklaf-core-2.5.4.jar:2.5.4]
	at com.github.weisj.darklaf.ui.filechooser.DarkFilePaneUIBridge$SortableListModel.<init>(DarkFilePaneUIBridge.java:1079) ~[darklaf-core-2.5.4.jar:2.5.4]
	at com.github.weisj.darklaf.ui.filechooser.DarkFilePane.createList(DarkFilePane.java:137) ~[darklaf-core-2.5.4.jar:2.5.4]
	at com.github.weisj.darklaf.ui.filechooser.DarkFileChooserUIBridge.createList(DarkFileChooserUIBridge.java:585) ~[darklaf-core-2.5.4.jar:2.5.4]
	at com.github.weisj.darklaf.ui.filechooser.DarkFileChooserUIBridge$MetalFileChooserUIAccessor.createList(DarkFileChooserUIBridge.java:750) ~[darklaf-core-2.5.4.jar:2.5.4]
	at com.github.weisj.darklaf.ui.filechooser.DarkFilePaneUIBridge.setViewType(DarkFilePaneUIBridge.java:376) ~[darklaf-core-2.5.4.jar:2.5.4]
	at com.github.weisj.darklaf.ui.filechooser.DarkFilePaneUIBridge.propertyChange(DarkFilePaneUIBridge.java:890) ~[darklaf-core-2.5.4.jar:2.5.4]
	at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:343) ~[?:?]
	at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:335) ~[?:?]
	at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:268) ~[?:?]
	at java.awt.Component.firePropertyChange(Component.java:8722) ~[?:?]
	at javax.swing.JComponent.setUI(JComponent.java:733) ~[?:?]
	at javax.swing.JFileChooser.updateUI(JFileChooser.java:1839) ~[?:?]
	at javax.swing.JFileChooser.setup(JFileChooser.java:396) ~[?:?]
	at javax.swing.JFileChooser.<init>(JFileChooser.java:362) ~[?:?]
	at javax.swing.JFileChooser.<init>(JFileChooser.java:309) ~[?:?]
	at org.apache.jmeter.gui.util.FileDialoger.<clinit>(FileDialoger.java:42) ~[ApacheJMeter_core.jar:5.4.1]
	at org.apache.jmeter.gui.action.Load.loadProjectFile(Load.java:156) ~[ApacheJMeter_core.jar:5.4.1]
	at org.apache.jmeter.gui.action.Load.loadProjectFile(Load.java:101) ~[ApacheJMeter_core.jar:5.4.1]
	at org.apache.jmeter.gui.action.LoadRecentProject.doActionAfterCheck(LoadRecentProject.java:71) ~[ApacheJMeter_core.jar:5.4.1]
	at org.apache.jmeter.gui.action.AbstractActionWithNoRunningTest.doAction(AbstractActionWithNoRunningTest.java:44) ~[ApacheJMeter_core.jar:5.4.1]
	at org.apache.jmeter.gui.action.ActionRouter.performAction(ActionRouter.java:87) ~[ApacheJMeter_core.jar:5.4.1]
	at org.apache.jmeter.gui.action.ActionRouter.lambda$actionPerformed$0(ActionRouter.java:69) ~[ApacheJMeter_core.jar:5.4.1]
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) ~[?:?]
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771) ~[?:?]
	at java.awt.EventQueue$4.run(EventQueue.java:722) ~[?:?]
	at java.awt.EventQueue$4.run(EventQueue.java:716) ~[?:?]
	at java.security.AccessController.doPrivileged(AccessController.java:399) ~[?:?]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) ~[?:?]
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:741) ~[?:?]
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) [?:?]
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) [?:?]
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) [?:?]
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) [?:?]
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) [?:?]
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) [?:?]
2021-10-13 20:27:57,826 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2021-10-13 20:27:57,827 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2021-10-13 20:27:57,829 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2021-10-13 20:27:57,830 INFO o.a.j.e.u.CompoundVariable: Note: Function class names must contain the string: '.functions.'
2021-10-13 20:27:57,832 INFO o.a.j.e.u.CompoundVariable: Note: Function class names must not contain the string: '.gui.'
2021-10-13 20:27:57,889 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2021-10-13 20:27:57,934 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2021-10-13 20:27:57,934 INFO o.a.j.e.StandardJMeterEngine: Starting 5 threads for group Thread Group.
2021-10-13 20:27:57,934 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2021-10-13 20:27:57,934 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=5 ramp-up=1 delayedStart=false
2021-10-13 20:27:57,938 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2021-10-13 20:27:57,942 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2021-10-13 20:27:57,942 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2021-10-13 20:27:57,953 INFO o.a.j.p.h.s.HTTPHCAbstractImpl: Local host = kiddMacBook-Pro.local
2021-10-13 20:27:57,964 INFO o.a.j.p.h.s.HTTPHC4Impl: HTTP request retry count = 0
2021-10-13 20:27:58,138 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-2
2021-10-13 20:27:58,339 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-3
2021-10-13 20:27:58,363 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2021-10-13 20:27:58,363 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2021-10-13 20:27:58,399 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-3
2021-10-13 20:27:58,399 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-3
2021-10-13 20:27:58,538 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-4
2021-10-13 20:27:58,585 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-4
2021-10-13 20:27:58,586 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-4
2021-10-13 20:27:58,738 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-5
2021-10-13 20:27:58,764 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-2
2021-10-13 20:27:58,764 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-2
2021-10-13 20:27:58,789 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-5
2021-10-13 20:27:58,789 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-5
2021-10-13 20:27:58,789 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2021-10-13 20:27:58,790 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

Modify the configuration: re run, the problem is solved perfectly

There was an unexpected error (type=Internal Server Error, status=500).Invalid bound statement (not

Full error:

The problem revolves around mapper. There may be many reasons for the problem:

1. The control document is written incorrectly

2. The file generated after compilation does not contain XML file

Solution: manually specify the resource folder in the pop file

<!--        Manually specify the resource folder-->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>

Hibernate Error: Error executing DDL “create table course (xxx)“

Error code:

Hibernate: create table course (id integer not null auto_increment, index integer, name varchar(255), primary key (id)) engine=InnoDB
Oct 12, 2021 4:31:05 PM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL "create table course (id integer not null auto_increment, index integer, name varchar(255), primary key (id)) engine=InnoDB" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table course (id integer not null auto_increment, index integer, name varchar(255), primary key (id)) engine=InnoDB" via JDBC Statement
...

Hibernate: create table student (id integer not null auto_increment, name varchar(255), primary key (id)) engine=InnoDB
...

Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'integer, name varchar(255), primary key (id)) engine=InnoDB' at line 1
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:762)
	at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:646)
	at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
	... 36 more

Finally, I found that the problem is that an attribute name of my Course class is index, and this is a keyword in MySQL

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "course")
@ManagedBean(name = "course")
public class Course {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;
    private Integer index;

    @ManyToMany(mappedBy = "courseList")
    private List<Student> studentList;

}

Just change the name of index

Summary: attribute names of entity classes should not be keywords in the database

[RFID] OctaneSDKJava Eclipse Error: Error occurred during initialization of boot layer

Question details

Errors are reported as follows:

Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\tongx\eclipse-workspace\OctaneSDKJava\lib\OctaneSDKJava-1.22.0.30-jar-with-dependencies.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: JDOMAbout$Info.class found in top-level directory (unnamed package not allowed in module)

Attempt method 1 (failed)

In jdk9 and above, modules are introduced. Therefore, if a separate running class is created in the default package, it cannot be compiled. There is no such problem in jdk8; If you still want to run separate classes in the default package, delete module-info.java in the SRC folder.

But my java is version 1.8, and my attempt failed

Try method 2 (feasible)

Here, we have adopted the methods of other big men:


end

CORS error has been blocked by CORS policy [How to Solve]

Problem description

The global request is intercepted through the axis of Vue. After adding the identify and token fields to the request header, the back-end zuul gateway is accessed. An error occurs in the browser, resulting in that the background cannot receive the custom header field of HTTP package and cannot authenticate the gateway well
the error is as follows:
access to XMLHttpRequest at‘ http://127.0.0.1:27000/api/v1/index -Infos’ from origin ‘http://’ has been blocked by CORS policy: request header field identification is not allowed by access control allow headers in preflight response.
network and console errors are as follows:

Error analysis

The background is cross-domain. An error occurs when a field is added to the header. In CORS, the options method will be used to initiate a pre-check request (generally, it will be automatically initiated when browsing detects that the request is cross-domain) to detect whether the actual request can be accepted by the server. The access control request method header field in the pre-check request message informs the server of the HTTP method used for the actual request
the access control request headers header field tells the server the custom header field carried by the actual request. The server determines whether to accept the next actual request based on the information obtained from the pre-check request. The access control allow methods header field returned by the server informs the client of all allowed request methods
to sum up, when the browser sends a request header with customization, the browser will first send an options pre-check request to the server to detect whether the server of the request allows customization of cross-domain fields. If yes, continue to execute the request. If not, an error message will be returned to prompt an error.

Solution:

Add the corresponding allow field in the cross domain request header and add your own custom field in the access control allow headers field. The request can be accessed. The interception code in zuul:

@Override
    public Object run() throws ZuulException {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        HttpServletResponse response = ctx.getResponse();

        response.setHeader("Access-Control-Allow-Origin",request.getHeader("Origin"));
        response.setHeader("Access-Control-Allow-Credentials","true");
        response.setHeader("Access-Control-Allow-Methods","GET, HEAD, POST, PUT, DELETE, OPTIONS, PATCH");
        response.setHeader("Access-Control-Allow-Headers","authorization, content-type,token,identify");
        response.setHeader("Access-Control-Expose-Headers","X-forwared-port, X-forwarded-host");
        response.setHeader("Vary","Origin,Access-Control-Request-Method,Access-Control-Request-Headers");

        if ("OPTIONS".equalsIgnoreCase(request.getMethod())){
            ctx.setSendZuulResponse(false); 
            ctx.setResponseStatusCode(HttpStatus.OK.value());
            ctx.set("isSuccess", true);
            return null;
        }
        ctx.setSendZuulResponse(true); 
        ctx.setResponseStatusCode(HttpStatus.OK.value());
        ctx.set("isSuccess", true);
        return null;
    }

Mac project startup error: logback configuration error detected

java.lang.illegalstateexception: logback configuration error detected:
when the company started the service, an error was reported, but there were no other problems at the same time. After checking for a long time, I checked the information on the Internet,
it was found that it was because I used a Mac computer. The path file configuration of the Mac computer was different from that of the window, and the MAC system, Log output location configured by logback. My computer does not have this path.

<property name="LOG_HOME" value="/Users/zero_/files/UNINETS-JAVA/Logs/log" />

Therefore, it is good to modify the location of the log path in the logback file configuration to its own path

Mapper.xml Error: Error setting non null for parameter #3 with JdbcType null.

Record the problems encountered in learning SSM framework 3
Exception Reporting
Message Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=‘id’, mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId=‘null’, jdbcTypeName=‘null’, expression=‘null’}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #3 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
Description The server encountered an unexpected condition that prevented it from completing the request.
The problem occurs mainly in the mapper.xml file and can be due to several reasons.
1. two #’s are written together and will be identified incorrectly (my error)

<update id="updateById" parameterType="main.java.com.dy.domain.News">
        update news
        <set>
            <include refid="News_update"/>
        </set>
        where id=##{id}
    </update>

2. JavaEE comments appear inside/**/

<update id="updateById" parameterType="main.java.com.dy.domain.News">
        update news
        <set> /*  */
            <include refid="News_update"/>
        </set>
        where id=#{id}
    </update>

3. #{id} covered with quotation marks

<update id="updateById" parameterType="main.java.com.dy.domain.News">
        update news
        <set>
            <include refid="News_update"/>
        </set>
        where id='#{id}'
    </update>

All the above detailed errors may lead to errors in the execution of SQL statements, so we should be as careful as possible in the future development process.

Uncaught SyntaxError: Unexpected token o in JSON at position 1 [How to Solve]

JSON.parse(str); Error prompted during method execution;

The solution is very simple. Just pay attention to the format of STR parameter, which must be in the standard JSON string format

var str = '[{"code": "name", "name": "name"},{"code": "name1", "name": "name1"}]';

If the str value is passed through the background, be sure to confirm whether the format is correct

[Solved] Hibernate Error: java.lang.StackOverflowError at java.lang.Integer.toString(Integer.java:402)

1. Problem Description:

When using hibernate to query the database, the data has been successfully found from the database, but an error is reported when looping through the output: java.lang.stackoverflowerror

2. Solution process:

2.1 this is my query method:

@Test
public void test01() {
     Session session = SessionFactoryUtil.getSessionFactory().openSession();
     String hql = "from Student";

     Query query = session.createQuery(hql);
     List list = query.list();
     list.forEach(System.out::println);
 }

2.2 this is an error message:

java.lang.StackOverflowError
	at java.lang.Integer.toString(Integer.java:402)
	at java.lang.Integer.toString(Integer.java:935)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at Course.toString(Course.java:16)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at java.util.AbstractCollection.toString(AbstractCollection.java:462)
	at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at Student.toString(Student.java:25)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at java.util.AbstractCollection.toString(AbstractCollection.java:462)
	at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at Course.toString(Course.java:16)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at java.util.AbstractCollection.toString(AbstractCollection.java:462)
	at org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:622)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at Student.toString(Student.java:25)
	......loop

2.3 check the error message and find that the top exception points to my Lombok annotation: @data

2.4 it is suspected that hibernate does not support Lombok

So I changed all the annotations to setter, getter and toString methods
and then reported the same error. This time, I pointed to the line of outputting courselist in the toString method of my student class

2.5 take a look at my two entity classes:

Student class:

@Data
@NoArgsConstructor
@AllArgsConstructor
@ManagedBean(name = "student")
@Entity(name = "student")
public class Student {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;

    @ManyToMany
    private List<Course> courseList;

}

Course class:

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "course")
@ManagedBean(name = "course")
public class Course {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;
    private Integer no;

    @ManyToMany(mappedBy = "courseList")
    private List<Student> studentList;
    
}

Note: student and course are many to many, so each class has a collection of each other

2.6 finding problems:

It is not difficult to find that there is a course collection courselist in the student class, and there is also a student collection studentlist in the course class. Therefore, when outputting, it enters a wireless loop process, which is briefly described as follows:

student -> course -> student->course...

3. Solution:

Delete the line that outputs studentlist in the tostring() method in the Course class, and only keep the line that outputs courselist in the student class. Or just keep the output of studentlist in the Course class

RSA Decryption Error: java.security.InvalidKeyException: IOException : algid parse error, not a sequence

To get a private key, you need to decrypt the encrypted data. I can’t figure it out. When I get the privatekey, I report an error algid parse error, not a sequence

KeyFactory.getInstance("RSA").generatePrivate(
                    new PKCS8EncodedKeySpec(Encodes.decodeBase64("priKey")))

The reason is that the private key string is not in PKCs #8’s format and cannot be transferred without using a third-party jar

One solution is to use OpenSSL to convert the private key string into pkcs#8 format

The second is to use the third-party library. I use the third-party library bouncy castle, which is more convenient and fast. I don’t bother to install OpenSSL

pom:

<dependency>
                <groupId>org.bouncycastle</groupId>
                <artifactId>bcprov-jdk15on</artifactId>
                <version>1.59</version>
            </dependency>
            <dependency>
                <groupId>org.bouncycastle</groupId>
                <artifactId>bcmail-jdk15on</artifactId>
                <version>1.59</version>
            </dependency>
            <dependency>
                <groupId>org.bouncycastle</groupId>
                <artifactId>bcpkix-jdk15on</artifactId>
                <version>1.59</version>
            </dependency>

Restore private/public key to PEM file

public static PrivateKey get10027504355PrivateKey() throws Exception {
        BufferedReader br=new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("config/10027504355ssl.pem")));
        PEMParser pemParser = new PEMParser(br);
        PEMKeyPair pemKeyPair = (PEMKeyPair)pemParser.readObject();
        pemParser.close();
        JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
        KeyPair keyPair = converter.getKeyPair(pemKeyPair);
        PublicKey publicKey=keyPair.getPublic();
        return keyPair.getPrivate();
    }

Add bouncycastleprovider when the application starts and initialize it once

package com.mktpay.admin.init;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.security.Security;

/**
 * @ClassName Runner
 * @Author yupanpan
 * @Date 2021/10/11 15:03
 */
@Component
public class EDncryptRunner implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        //Customize other ways to initialize encryption and decryption algorithms
        Security.addProvider(new BouncyCastleProvider());
    }
}