The new project uses IDEA to build the back-end environment and build the possible problems and solutions

Tip: After the article is written, the table of contents can be automatically generated. How to generate it can refer to the help document on the right

The new project uses IDEA to build the back-end environment and build the possible problems and solutions

foreword

提示:这里可以添加本文要记录的大概内容:

The new project uses IDEA to build the back-end environment and build the possible problems and solutions

Reminder:
Before building, first read the user manual carefully, so as to facilitate the smooth and fast building of the project environment in the later stage

The following figure shows the editor used during development
insert image description here


提示:以下是本篇文章正文内容,下面案例可供参考

1. Programming language and framework

java

Two, steps

1. Open the idea

insert image description here

2. Import project

insert image description here

3. Select the directory where the project backend file is located

insert image description here

4. Configure the port

Pay special attention to whether the port in the configuration file is occupied. Generally, we use port 8080.
If it is displayed that port 8080 is occupied at startup, we need to change a port number (note: but at the same time, the default port number of the front end should also be changed. Corresponding changes, and should be consistent with the changed port number, the specific modification steps are viewed in the front part)
insert image description here

5. Download related dependencies and jar packages

insert image description here

5. Configure redis required for the project

insert image description here
insert image description here

6. Redis required to start the project

insert image description here

Check whether redis has been downloaded, whether the status is started, and one more thing to pay attention to is the password of redis in the configuration

insert image description here

6. Matters needing attention:

The application-dev.yml file configuration in Java is shown in the figure below (pay special attention to the format)

#redis 配置
redis:
  open: true  # 是否开启redis缓存  true开启   false关闭
  database: 0
  host: 127.0.0.1
  port: 6379
  password:    # 密码(默认为空)
  timeout: 6000ms  # 连接超时时长(毫秒)
  jedis:
    pool:
      max-active: -1  # 连接池最大连接数(使用负值表示没有限制)
      max-wait: -1ms      # 连接池最大阻塞等待时间(使用负值表示没有限制)
      max-idle: 10      # 连接池中的最大空闲连接
      min-idle: 5       # 连接池中的最小空闲连接

Pay special attention : sometimes localhost may not be easy to use during configuration, so we'd better configure 127.0.0.1 to point to our computer
or configure the IP address of our computer directly to the server we use.

Summarize

Tip: Summary:

1. The project uses dependencies and jar packages
The dependencies or jar packages used in the project, because we are importing a new project, if the following error message appears when starting
Error: (4, 25) java: cannot find symbol Symbol: class xxx location : Package xxx.xxx
Then, we should first install or download related jar packages and dependent files used

2. Relevant configurations used when compiling the project
Whether the configuration items related to jdk, tomcat, maven, etc. used in the project are set in the idea

3. .spring annotations
We must correctly understand the use of spring-related annotations, and use relevant annotations correctly when using:
(1), @Import

@Import注解可以导入如下四种类型:

导入普通类      

导入带有@Configuration的配置类       

通过ImportSelector 方式导入的类       

通过 ImportBeanDefinitionRegistrar 方式导入的类 

Function:
This annotation is written on the class and is usually used with annotation-driven configuration classes. Its role is to introduce other configuration classes. After using this annotation, we can make our annotation-driven development the same as the early XML configuration, and configure different content separately to make the configuration clearer. At the same time, after specifying this annotation, annotations such as @Configuration and @Component can no longer be used on the imported class.
Attributes:
value:
Bytecode used to specify other configuration classes. It supports specifying multiple configuration classes.
For ImportSelector and ImportBeanDefinitionRegistrar, please refer to the advanced analysis of the @Import annotation in Section 7 of Chapter 5.
Usage scenario:
When we use annotation-driven development, because there are too many configuration items, if they are all written in one class, the configuration structure and content will be messy. At this time, using this annotation can configure the configuration items in different categories.

(2), @Autowired
function:
automatically inject according to the type. When there is only one type matching in the ioc container, it can be directly injected successfully. When there is more than one match, use the variable name (written on the method is the method name) as the bean id, match again in the bean that matches the type, and the injection can be successful if it can match. When the match fails, whether to report an error depends on the value of the required attribute.
Attributes:
required:
Whether the injection must be successful. The default value is true, indicating that the injection must be successful. When the value is true, an error will be reported if the injection is unsuccessful.
Usage scenarios:
There are many usage scenarios of this annotation, and it is widely used in actual development. Usually, this annotation can be used when injecting dependent bean objects into classes we write ourselves.
Note:
@Autowired is assembled by type by default. If we want to use assembly by name, we can use it in conjunction with the @Qualifier annotation.
@Autowired @Qualifier("personDaoBean") has multiple instances for use together

(3), @Configuration
@Configuration takes a class as an IoC container, and if @Bean is registered on one of its method headers, it will be used as a Bean in this Spring container.
(4), @Scope
@Scope annotation scope
(5), @Lazy(true)
@Lazy(true) indicates delayed initialization
(6), @Service
@Service is used to mark business layer components,
(7) @Controller
@Controller Used to mark control layer components (such as actions in struts)
(8), @Repository
@Repository is used to mark data access components, namely DAO components.
(9), @Component
@Component refers to components in general. When components are not easy to classify, we can use this annotation to mark them.
(10), @Scope
@Scope is used to specify the scope scope (used on the class)
(11), @PostConstruct
@PostConstruct is used to specify the initialization method (used on the method)
(12), @PreDestory
@PreDestory is used Specify the destruction method (used on the method)
(13), @Resource
@Resource is assembled by name by default, and will be assembled by type when no bean matching the name is found.
(14), @DependsOn
@DependsOn: Define the order of Bean initialization and destruction
(15), @Primary
@Primary When multiple Bean candidates appear during automatic assembly, the Bean annotated as @Primary will be the preferred one, otherwise an exception will be thrown
Here we First record some commonly used annotations and related instructions

Guess you like

Origin blog.csdn.net/YHLSunshine/article/details/129218499