Tag Archives: back-end

Web: xssfworkbook error NoClassDefFoundError [How to Solve]

I. background introduction

The Java Web environment needs to read the data in the excel table and insert it into the database. The xssfworkbook class needs to be used to read the table file. The key codes are as follows:

  //read excel
    public static Workbook readExcel(String filePath) {
        Workbook wb = null;
        if (filePath == null) {
            return null;
        }
        String extString = filePath.substring(filePath.lastIndexOf("."));
        InputStream is = null;
        try {
            is = new FileInputStream(filePath);
            if (".xls".equals(extString)) {
                return wb = new HSSFWorkbook(is);
            } else if (".xlsx".equals(extString)) {
                return wb = new XSSFWorkbook(is);
            } else {
                return wb = null;
            }

        } catch (FileNotFoundException e) {
            LOGGER.error(e.toString());
        } catch (IOException e) {
            LOGGER.error(e.toString());
        } 
        return wb;
    }

II. Occurrence of problems

Running locally, such as writing a main method or running with @ test, can run normally, but on the web, the interruption point finds that this class cannot be found
so it tries to upgrade the dependency package

or not. Unable to solve it, he fell into deep thinking. It’s really hard to deal with environmental problems and dependency problems
tried the recommended dependencies and versions given by other authors, but still failed:
First:

Second:

Three problem solving

Bypass the problem. If the mountain doesn’t come, I’ll go
change the file format: that is, xlsx is XLS, and finally return to the hssfworkbook class for reading.

PATH = "/Users/xxx/work/B/A_info.xlsx";

by

PATH = "/Users/xxx/work/B/A_info.xls";

So you can access it in the web layer
(PS: it should be noted that if you directly change the. Xlsx format file to. XLS, you need to open the file first and click Save as. XLS format. You can’t be lazy here. The author has also stepped on this pit)

Exception handling of httpmessage notwritableexception in springboot

preface:

First, post the error report log

Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class com.test.dto.ResultBean]

If the log is similar, you can continue to look down.

1. Causes and Solutions

Restore the accident scene first (only show the core problem code)

Interface layer code:

@RestController
@RequestMapping("/client")
public class ControllerTest {

    @GetMapping("/test")
    public ResultBean name() {
        return ResultBean.success();
    }
}

ResultBean Code:

public class ResultBean {

    private String code;
    private String result;

    ResultBean(String code, String result) {
        this.code = code;
        this.result = result;
    }

    public static ResultBean success() {
        return new ResultBean("200", "success");
    }

}

The error log points to this   ResultBean. The big probability is that there is a problem with this bean. After careful analysis of the log, it probably means that it is impossible to get the value, so it is impossible to write. Get the value?Get method?It seems that ResultBean is missing the get method (Lombok annotation is forgotten). With the get method, the problem is solved

Tips: be sure to add get and set methods and try to write by hand; Lombok annotations are rarely used. There are holes in them. Occasionally, the default method for generating special fields cannot be recognized by other components.

[Solved] 530 This server does not allow plain FTP. You have to use FTP over TLS

FileZilla Server You have to use FTP over TLS”, you can check the message when you use “530 This server does not allow plain FTP.
The message is: 530 This server does not allow plain FTP. You have to use FTP over TLS

Solution:
Click EDit –> Settings –> FTP over TLS setting, uncheck **Enable FTP over TLS support(FTPS)** and it will be OK (so that the encryption method does not use explicit FTP over TLS)

[Solved] Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerExcepti

 

1、 Background description

Project architecture: spring boot (v2.0.0. Release) + mybatis plus (v3.1.1)

Today, I developed a new function on an old project (running normally). Before adding new functions, the project started and ran normally. As a result, after the development, the project couldn’t start and the background didn’t report any error information. The key is that I didn’t even have a log. For a moment, I couldn’t start it.

2、 Cause analysis

According to the situation analysis, the project can’t be started. Thinking that there must be a problem in starting, a try… Catch… Block is added to the line of starting the project in the starting class (that is, the following code plus).

SpringApplication.run(DailyApplication.class, args);

See if there is an error log.

@Slf4j
@EnableScheduling
@EnableFeignClients(basePackages = "com.iot")
@SpringBootApplication(scanBasePackages={"com.iot"})
@MapperScan({"com.iot.daily.*.dao"})
public class DailyApplication implements ApplicationRunner {

    public static void main(String[] args) {
        try {
            SpringApplication.run(DailyApplication.class, args);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("error: ============== ", e);
        }
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("The daily report system was successfully launched!......");
    }
}

Start the project, and then, as expected, the console displays the error log with the following error message:

Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

The specific error information will be supplemented later, but now it can’t be reproduced.

3、 Solutions

Here is my project solution, very simple, Maven clean once, and then restart.

end!

JDK installation exception link it with ‘- Z noexecstack’ and inux 64 bit zendguardloader.so: wrong elf class: elfclass32 error handling

N1.
It’s highly recommended that you fix the library with ‘execstack -c <libfile>’, or link it with ‘-z noexecstack’.
It means that it is recommended to use sunjdk instead of linux’s own openjdk

N2.linux 64bit system ZendGuardLoader.so: wrong ELF class: ELFCLASS32 error
1. Download Zend Guard
32位 http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
64位 http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
mkdir /usr/local/zend
tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
sudo cp ZendGuardLoader-php-5.3-linux-glibc23-i386/php5.3.x/ZendGuardLoader.so /usr/local/zend/
2. Set
vim /etc/php.ini
Finally add.
zend_extension=/usr/local/zend/ZendGuardLoader.so
The reason for the above error is that the 64-bit system is using the 32-bit ZendGuardLoader.so.
The solution is to download a 64-bit ZendGuardLoader.so file that corresponds to the PHP version
1、Download Zend Guard
32位 http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
64位 http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
mkdir /usr/local/zend
tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
sudo cp ZendGuardLoader-php-5.3-linux-glibc23-i386/php5.3.x/ZendGuardLoader.so /usr/local/zend/
2. Set
vim /etc/php.ini
Finally Add:
zend_extension=/usr/local/zend/ZendGuardLoader.so

Tomcat memory overflow in Eclipse: Java. Lang. outofmemoryerror: permgen space solution:

1. Configure the size of this part of heap memory through the JVM parameter – XX: maxpermsize = 256M.  

2. How to configure the memory size of Tomcat in eclipse?

First, you need to double-click Tomcat server, as shown in the figure below:

Double click the figure above to display the Tomcat configuration interface

Then, click the link in the red rectangular box in the figure above, and the node of Tomcat parameter configuration will pop up. To select the arguments parameter box:

As shown in the figure above, you can set the value of – XX: maxpermsize = 256M in the VM arguments text box. Of course, you can add other JVM parameters, such as maximum memory, minimum memory, etc.

Frequent log swiping after Nacos client starts [How to Solve]

# 1, according to the heartbeat log, locate the package name of the log output
c.a.n.client.config.impl.ClientWorker : get changedGroupKeys:[]

# 2. Search the package path where ClientWorker is located in IDEA  
package com.alibaba.nacos.client.config.impl;

# 3. Set the package path logging to ERROR or WARN in any configuration file format
# Nacos registry client heartbeat logging is disabled get changedGroupKeys:[] 
logging:
  level:
    com.alibaba.nacos.client.config.impl: WARN
  
# 4. If it is Spring Cloud Gateway then you need to configure it as logging:
  level:
    com.alibaba.nacos.client.*: WARN    

For the problem of rejecting old usage errors after numpy is updated, modified in numpy 1.20; for more details and guidance

There’s something wrong with numpy

Because the latest version of numpy is updated today, the previous usage is invalid

So You need to use the latest usage

Originally, my return value is like this

return np.array(df).astype(np.float)

Error:

DeprecationWarning: np.float is a deprecated alias for the builtin
float. To silence this warning, use float by itself. Doing this
will not modify any behavior and is safe. If you specifically wanted
the numpy scalar type, use np.float64 here.

Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
return np.array(df).astype(np.float)

It seems to be because of the version of the problem

If you look at the picture
Modify to the following can be.

return np.array(df, dtype=float)

perhaps

return np.array(df).astype(np.float64)

So you won’t make a mistake

Spring boot integrates Mongo to solve some common connection and permission problems. Docker compose installs Mongo

Spring boot integrates Mongo to solve some common connection and permission problems. Docker compose installs Mongo

1、 Docker compose to install Mongo

version: '3.1'

services:

  mongo:
    image: mongo
    container_name: mongo
    restart: always
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: 123456

  mongo-express:
    image: mongo-express
    container_name: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_SERVER: mongo
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: 123456

2、 Spring boot integrates Mongo

Maven dependency

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

There are some points to pay attention to in the yaml configuration of springboot

1、 How to configure URI

1. Using the URI configuration method to configure password, user name, etc. will not take effect

2. If you encounter permission problems, check whether the user name and password match first. If you encounter

Command failed with error 17 (ProtocolError): ‘Attempt to switch database target during SASL authentication.

This kind of error report usually ends?Authsource = admin without

spring:
  data:
    mongodb:
      uri: mongodb://root:[email protected]:27017/demo?authSource=admin

2、 Configuration of traditional SQL

1. If you are a pure digital password, for example, the author’s password is 123456, use single or double quotation marks when configuring, otherwise you will be identified incorrectly, because the receiving password uses char array, and 123456 will obviously overflow

spring:
  data:
    mongodb:
      username: root
      password: '123456'
      host: 192.168.50.150
      port: 27017
      database: demo
      authentication-database: admin

TypeError: connection.connect is not a function

Today, when I wrote node.js to operate the database, I encountered a typeerror: connection.connect is not a function when setting up the database connection. The following is the bug prompt, as shown in the figure

when I found this error, I immediately went to connection.connect, but I didn’t find anything wrong,
For this reason, I made a special effort to find the previous code and compare it. The following is the thinking at that time

later, I asked my friend to check the custom module
PS: after staring at it for more than ten minutes, I didn’t find the error. At this moment, I felt like a mentally retarded person

later, I had to check one by one, I found that my mistake was to write the return value of the function as an object….. Verification complete….. Retarded stone hammer…..

Change it to the following way

rerun

egg.js The frame post request reported an error of invalid CSRF token security verification, which has been solved

It has to be said that Alibaba’s egg framework is quite good, with its own security verification.

Problem: get request is normal, post request background will report such an error.

" nodejs.ForbiddenError : invalid csrf token"

There is an official explanation for this problem. Click to jump to the official safety explanation of egg. There is not too much explanation here

Method 1: in the confit.default.js Add the following code to turn off security verification (not recommended)

config.security = {
    csrf: {
      enable: false,
    },
  };

Method 2: when the front-end initializes the interface, let the front-end get to request an interface first, and the background returns a secret key to the front-end. Let the front-end put it in the headers request header when the post request is made, and the egg will automatically verify the secret key, and the request will succeed only if the verification is successful.

1. Egg background code, get interface returns secret key: 2

async index() {
    const { ctx } = this;
    ctx.body = {
      csrf:ctx.csrf
    };
}

The following two methods are demonstrated. The postman test is as follows. At the same time, if a request is made in the front end, a secret key pair will be generated in the cookies. As shown in the figure below, the secret key will change after each request, so the CSRF obtained in the front end should be put in the headers request header in a global way.

2. Front end secret key request: 2

axios.post('apis/add', data,{headers:{'x-csrf-token': headData}})

The postman test is as follows: directly copy CSRF

OK, successful request, perfect solution, start moving bricks

Solve rstudio software error: fatal error error system error 5 (access denied) problem, pro test effective

1. Error reporting:

2. Error report: because the current system user name is in Chinese, there is a garbled code when reading the path, which cannot be recognized.

3. Solution: modify the values of the current user’s environment variables temp and TMP. Change the variable value to a path without Chinese name.

4. Restart rsudio software: the software can be used normally.