Tag Archives: JavaWeb

Spring MVC project error: Namespace in turns red

Namespace in <mapper namespace> turns red

Solution:

The XML file header language should be changed to the mapper mapping instead of the config
previously used as follows:

<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

Change to

<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

Create folders with different functions

[Solved] Tomcat runs JavaWeb servlet Error 404

Problem description

A new server template project is built with idea. After Tomcat is configured, the access report 404
is accessed

reason

Tomcat cannot load message 404 because war is not loaded

Solution:

An error occurs because the war artifact of this project is not loaded. You need to import this project as a artifact

and then select war_ Compared with war, the structure of the artifact will be consistent with the source directory for easy development

now the URL is the home page of the artifact by default

access

[Solved] Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred.

Error: could not create the Java virtual machine.
error: a fatal exception has occurred.program will exit

After I reinstalled eclipse, Tomcat reported this error when running JSP
Google has various solutions, some say Java, some say JDK, and some say Tomcat. They can’t use

Solution: just reset a workspace

The idea code pushes to GitHub and reports an error fatal: unable to access

Error:

fatal: unable to access ‘ https://github.com/ …


terms of settlement:

1. Execute SSH keygen – t RSA on the idea terminal and press enter to generate the public key and private key. By default, it is saved in the. SSH directory under the user directory of Disk C
2. Find settings in the GitHub homepage, as shown in the figure below. Create a new SSH
note: when creating a new SSH, fill in the ID_ Contents in rsa.pub
3. Set the private key in idea


Reference link: https://blog.csdn.net/qianlixiaomage/article/details/114681364

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)

[Error][IntelliJ IDEA] Element XXX is not allowed here

Questions

When using IntelliJ idea to build a project, errors such as element XXX is not allowed here are encountered in the XML file

For example, the following element resultmap is not allowed here error is encountered in the XML configuration file

resolvent

The configuration of the header of the XML file is wrong, and the names of the three places in the red box should be consistent

[Solved] Connections could not be acquired from the underlying database

There has been this bug in the past two days. Record the solution and summary.

Solution:

1. Driver configuration error (my bug) 

2. Database connection address error

3. Account password error

4. The database is not started or has no right to access, such as without networking 

5. The version does not correspond to (my bug) 

6. Driver jar package is not introduced into the project

My MySQL jar package is 5.0.8, but my MySQL server is 8.0, so I can change it to 5.1.46!

Mysql-connector-java-5.1.46-bin.jar download address:

Download address

We can find out the reason according to the actual situation.

Using AspectJ to transfer the data written to FTP service to MySQL database

Recently, the company’s project has carried out the rectification of performance improvement. It was originally planned to use FTP to write the collected underlying data to the file, and the client will read the FTP file again, and then parse and display it according to the demand. In the actual application process, the display effect is not ideal due to the slow reading and parsing of the FTP file. Therefore, it is proposed that the data written to FTP should be parsed and stored in the database for the client Read the database directly, no need to read the file and parse, so as to improve the display effect and performance of this part.

After several options, in the light of minimal changes and smooth transition, the original part of FTP writing remains intact, and the client’s parsing display function is also retained. Using AspectJ, the method of writing FTP file (upload ()) is pointcut. Once FTP writes a file, the operation of writing database part is triggered. First, the parameters of upload () are obtained, and these parameters are parsed , stored in a global list, the SQL method will construct the insert statement through the global list, and finally addbatch will execute and submit. Considering that frequent connection to the database for insertion will seriously affect the performance, the insert operation is set as a scheduled task, and the corresponding insert will be constructed according to the global list every 60 seconds SQL, execute and submit transactions, so as to reduce the pressure of the database and clear the current list; in order to ensure data security, the insert and list clear operations are placed in a synchronized statement segment to prevent the list from being changed when constructing SQL. So far, the transfer of the original FTP data is completed.

Advantages: 1. Aspect programming, without affecting the original system architecture and business code, realizes the optimization of functions, and still maintains loose coupling;

2. Keep the original function and make a smooth transition;

Paste part of the code as follows (integrated development under the spring framework)

@Aspect

@Enable scheduling
@ enable aspect jautoproxy// enable aspect proxy
@ component()
public class dbsyncaop{

//Set upload (..) to pointcut and name it pointcustsignature ()

@Pointcut(“execution(* com.bjtct.oom . mms.service.FileManager .upload(..))”)
public void pointcustSignature(){}

//2. Set the loading priority of the uploadfileaspect method to high and load it first

@Around(“pointcustSignature()”)
@Order(value=1)
public Object uploadFileAspect(ProceedingJoinPoint pjp) throws Throwable{

//upload() execute before ,get upload() paramaters code here 

List<String> fileNames = (List<String>) pjp.proceed ();

//upload() execute after ,handle upload() paramaters  here,and store data in mysql code here 

//handle upload() paramaters

List<Map<String, String>> fieldMapList = handleMsg(type, mqMsg);  

//param is a global list. Here, the data originally written to FTP is saved to param, which is used to construct the inserted SQL statement

synchronized(params){
List<Object> param;
for(int i=0; i< fieldMapList.size (); i++){
param = new ArrayList<Object>();
msg = fieldMapList.get (i);
System.out.println (“msg: “+msg);
param.add (new Date());
param.add (msg);
param.add (type);

params.add (param);
}
}

//Schedule tasks regularly, execute the method regularly, and insert the data obtained from FTP

@Scheduled(cron = “${ DBSync.schedule.delay .cron}”)
private void proceedInsertion(){

if(!”Y”.equalsIgnoreCase(DBSyncEnabled)){
return;
}
log.info (“DBSyncAop scheduling start”);
Connection conn = null;
PreparedStatement ps = null;
log.info (“##params size: “+ params.size ());
synchronized(params){
if(! params.isEmpty ()){
try{
conn = DataSourceUtils.getConnection (scheduleDataSource);
conn.setAutoCommit (false);
List param;
ps = conn.prepareStatement (insertSql);
for(int i=0; i< params.size (); i++){
param = params.get (i);
ps.setDate (1, new java.sql.Date (((Date) param.get (0)).getTime()));//timestamp
ps.setString (2, (String) param.get (1));//fileName
ps.setString (3, (String) param.get (2)); //json msg
ps.setString (4, (String) param.get (3));//mq type
ps.addBatch ();
log.info (“DBSyncAop scheduling added batch”);
}
ps.executeBatch ();
conn.commit ();
log.info (“DBSyncAop scheduling committed”);
conn.setAutoCommit (true);
params.clear ();
} catch (Exception e) {
log.error (“insert MQ information data contact” + e.getmessage());
e.printstacktrace();
} finally {
try {
} DataSourceUtils.doCloseConnection (conn, scheduleDataSource);
} catch (SQLException e) {
log.error (e.getMessage());
e.printStackTrace();
}
}
}
}
log.info (“DBSyncAop scheduling finish”);

}

}

Yapi platform deployment error (MAC must report error) solution

1. Deploy Yapi locally

According to the official documents, after the global installation of Yapi CLI and mongodb, the terminal executes Yapi server, and the browser enters 127.0.0.1:9090 to open the deployment page

After filling in the basic information, click Start deployment, wait for a period of time, the problem appears

node server/install.js

Error:internal/modules/cjs/loader.js:584
   throw err;

Errpr:Cannot find module 'nodemailer'
  at Function.Module_resolveFileName(.........)
  at Function.Module_resolveFileName(.........)
  ........

   

The reason for the error is probably the lack of nodemailer module, so I tried to install the module globally. After the installation, I still reported the same error. In this way, I kept looking for the error. I deleted the project and started over again. After repeated tossing and tossing, I was about to re install the system. After one afternoon’s tossing and tossing, I finally found a solution

2. Solutions

Due to the problem of MAC permission, Yapi is initialized according to the official document writing method, and finally there is no write permission in NPM, resulting in the loss of packets

Modify the “Yapi server” as

sudo yapi server

Then the project is deployed again and the problem is solved