"Build your own server with Java" journey

main content

This article mainly records the problems encountered in the process of building the server and the corresponding solutions. In order to avoid things that you understand after spending a lot of time, gradually forgetting over time or encountering similar problems later will take time to query again, so it is recorded here. Since I am not a back-end worker, I only stayed on some names for the back-end technology stack before, so there will inevitably be omissions in the article, and I hope to correct it, thank you.

This article is based on Java - Build your own RESTful API server (SpringBoot, Groovy) article, so if you need to build a server, please refer to this article.

origin

I want to build a backend quickly, but I have no backend experience. So I searched for information on the Internet and found a more detailed tutorial. If you want to know the specific steps, you can go to Java - build your own RESTful API server (SpringBoot, Groovy). Here, I would like to thank the original author for fulfilling my wish. Although I have a basic understanding, I encountered many problems during the construction process, so with the mentality of being able to quickly understand new technologies, I summarized the problems encountered.

problem and solution

1. Create a Maven project

Since the maven project is created in the referenced article, this problem cannot be avoided. For an android developer, he has used gradle to create projects, so he is very unfamiliar with maven.

The specific creation process will not be described in detail, please refer to IntelliJ IDEA 15 to create a maven project . If you don't know how to build a maven project, you can refer to Introduction to Maven (2) - Basic Concepts . Have a general understanding of maven (basic configuration, project directory structure, etc.) Although it is under eclipse, it has little impact.

Finally, summarize the basic steps to create a maven project: create a new project (project naming, project path setting):

Project Naming Project Path Settings —> Configure project-structure (Modules–Facts–Aftifacts)–>Deployment Server (Tomcat)

2. The project language is groovy,
although it seems a little awkward for java users who write android, it is still acceptable.
Solution: As shown in the figure:
insert image description here
Right-click to select the grovvy class to be operated and select Rrefactor —> Convert to java
3. How to create the data in the reference tutorial?
After almost configuring it according to the previous tutorial, I suddenly realized a very serious problem. What about the data? How to get? This is a bit difficult for me who has never developed a backend and does not understand the project directory structure. After trying to place HTML xml and other files in the webapp directory to no avail, I searched for information on the Internet to understand the basic configuration and concepts of the maven configuration file. Finally, insert image description here
I found the database query statement in the file, so I realized that the data should be stored in the database.
So create a database mysql in idea. It should be noted here that before configuring, make sure that the database you want to create already exists in mysql, otherwise you cannot connect successfully by clicking test connect during the configuration process.
insert image description here
To start the mysql database, enter show databases; (with a semicolon) to view, if not, use
create database database name; to create a database. After everything is ready, you can add the corresponding data to the database according to the example.

4. Encountered the Application startup failed error when starting the application.
I was a little panicked if I hadn’t touched it before. Since it was recorded after the solution, I can’t remember it clearly. The initial report was not only this error, but also Unable to start embedded container. Refer to the spring-boot service startup report: Unable to start embedded container Due to the inconsistency of the compilation environment, I have tried all the possibilities and failed to solve the problem.

Finally referred to one possible Tomcat version in the comments. First start Tomcat in the idea and find that the version is 7.0.86. This has been confirmed in the configuration.
server version
Then turn off Tomcat, run the application and find that the version is 8.5.6. during application
After careful comparison, it is found that the Tomcat package is used in the application. So refer to Spring Boot: Method 2 in the summary of built-in tomcat startup and external tomcat deployment is added in pom.xml

<!--部署成war包时开启↓↓↓↓-->
    <dependencies>
                 ...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <!--部署成war包时开启↑↑↑↑-->
               ...
    </dependencies>

Solution after running
So far, the sample project can basically run normally

write at the end

reference article

Java——Build your own RESTful API server (SpringBoot, Groovy)
IntelliJ IDEA 15 Create a maven project
Maven first introduction (2)——Basic concept
spring-boot service startup report: Unable to start embedded container
Spring Boot: built-in tomcat startup and external Tomcat deployment summary

Guess you like

Origin blog.csdn.net/fighting_2017/article/details/89927992