主頁 > 作業系統 > 當我運行SpringBoot測驗用例時出現錯誤,我無法自行解決

當我運行SpringBoot測驗用例時出現錯誤,我無法自行解決

2022-03-28 20:48:35 作業系統

我正在為我的控制器創建測驗用例

package com.bank.controller;

import static org.assertj.core.api.Assertions.assertThat;

import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.http.MediaType;
import com.bank.model.Account;
import com.bank.model.Customer;
import com.bank.service.AccountService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;


@RunWith(SpringRunner.class)
@WebMvcTest(value=AccountController.class)
class AccountControllerTest{

    @Autowired
    private MockMvc mockMvc;
    @MockBean
    private AccountService accountService;
    
    
    @Test
    public void testcreateAccount() throws Exception{
         Customer customer=new Customer();
         customer.setCustomerId(1);
         customer.setCustomerName("Manasa");
         
        Account mockAccount=new Account();
        mockAccount.setAccountNumber(456);
        mockAccount.setBalance(2000.0);
        mockAccount.setAccountType("savings");
        mockAccount.setCustomer(customer);
        
        
        String inputInJson=this.mapToJson(mockAccount);
        String URI="/account";
        Mockito.when(accountService.accountCreate(Mockito.any(Account.class))).thenReturn(mockAccount);
        RequestBuilder requestBuilder=MockMvcRequestBuilders
                .post(URI)
                .accept(MediaType.APPLICATION_JSON).content(inputInJson)
                .contentType(MediaType.APPLICATION_JSON);
        MvcResult result=mockMvc.perform(requestBuilder).andReturn();
        MockHttpServletResponse response=result.getResponse();
         String outputInJson=response.getContentAsString();
         assertThat(outputInJson).isEqualTo(outputInJson);
         assertEquals(HttpStatus.OK.value(),response.getStatus());
        
    }

    
    @Test
    public void testaccountList() throws Exception{
        
         Customer customer1=new Customer();
         customer1.setCustomerId(1);
         customer1.setCustomerName("Manasa");
         
        
        Account mockAccount1=new Account();
        mockAccount1.setAccountNumber(456);
        mockAccount1.setAccountType("savings");
        mockAccount1.setBalance(2000.0);
        mockAccount1.setCustomer(customer1);
        
         Customer customer2=new Customer();
         customer2.setCustomerId(2);
         customer2.setCustomerName("Madhu");
        
        Account mockAccount2=new Account();
        mockAccount2.setAccountNumber(789);
        mockAccount2.setAccountType("savings");
        mockAccount2.setBalance(6000.0);
        mockAccount2.setCustomer(customer2);
        
         Customer customer3=new Customer();
         customer3.setCustomerId(3);
         customer3.setCustomerName("Lalasa");
         
        
        Account mockAccount3=new Account();
        mockAccount3.setAccountNumber(123);
        mockAccount3.setAccountType("savings");
        mockAccount3.setBalance(50000.0);
        mockAccount3.setCustomer((Customer)Arrays.asList(3,"Lalasa"));
        
        List<Account> accountList=new ArrayList<>();
        accountList.add(mockAccount1);
        accountList.add(mockAccount2);
        accountList.add(mockAccount3);
        
        Mockito.when(accountService.allAccounts()).thenReturn(accountList);
        
        String URI="/account/aclist";
        RequestBuilder requestBuilder=MockMvcRequestBuilders.get(
                URI).accept(MediaType.APPLICATION_JSON);
        
        MvcResult result=mockMvc.perform(requestBuilder).andReturn();
        String expectedJson=this.mapToJson(accountList);
        String outputInJson=result.getResponse().getContentAsString();
        assertThat(outputInJson).isEqualTo(expectedJson);   
        
    }
    
    @Test
    public void testbyAccountType() throws Exception{
        
         Customer customer=new Customer();
         customer.setCustomerId(1);
         customer.setCustomerName("Manasa");
         
        
        Account mockAccount=new Account();
        mockAccount.setAccountNumber(456);
        mockAccount.setAccountType("savings");
        mockAccount.setBalance(2000.0);
        mockAccount.setCustomer(customer);
        
        String expectedJson=this.mapToJson(mockAccount);
        Mockito.when(accountService.accountByType(Mockito.anyString())).thenReturn((List<Account>) mockAccount);
        
        String URI="/account//byType/savings";
        RequestBuilder requestBuilder=MockMvcRequestBuilders.get(
                URI).accept(MediaType.APPLICATION_JSON);
        
        MvcResult result=mockMvc.perform(requestBuilder).andReturn();
        String outputInJson=result.getResponse().getContentAsString();
        assertThat(outputInJson).isEqualTo(expectedJson);       
        
    }
    
    
    private String mapToJson(Object object) throws JsonProcessingException{
        
        ObjectMapper objectMapper=new ObjectMapper();
        return objectMapper.writeValueAsString(object);     
            
    }
}

我的控制器類是

package com.bank.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bank.model.Account;
import com.bank.service.AccountService;
import com.bank.Exception.ResourceNotFoundException;

@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    AccountService accountService;
    
    @PostMapping
    public ResponseEntity<?> createAccount(@RequestBody Account account) throws ResourceNotFoundException{
        Account acc=accountService.accountCreate(account);
        if(acc!=null) {
            return new ResponseEntity<>(acc,HttpStatus.CREATED);
        }else {
        throw new ResourceNotFoundException("Account is not Created!!");
        }   
    }
    
    @GetMapping("/aclist")
    public ResponseEntity<?> accountList() throws ResourceNotFoundException{
        
        List<Account> accountList=accountService.allAccounts();
        if(!(accountList.isEmpty())) {
            return new ResponseEntity<>(accountList,HttpStatus.OK);
        }else {
            throw new ResourceNotFoundException("accounts not found");
        }
        
    }
    
    @GetMapping("/byType/{accountType}")
    public ResponseEntity<?> byAccountType(@PathVariable String accountType) throws ResourceNotFoundException{
        List<Account> account =accountService.accountByType(accountType);
        if(account.isEmpty()) {
            throw new ResourceNotFoundException(accountType "" "Type of account does not exist!!");
        }else {
            return new ResponseEntity<>(account,HttpStatus.OK);
        }
    }
    
    @GetMapping("/{accountNumber}")
    public ResponseEntity<?> getAccountById(@PathVariable("accountNumber") int accountNumber) throws ResourceNotFoundException{
        Account acc=accountService.findAccountById(accountNumber);
        if(acc!=null) {
            return new ResponseEntity<>(acc,HttpStatus.OK);
        }else {
            throw new ResourceNotFoundException("account [accountNumber=" accountNumber "] can't be found");
        }
    }

    @PutMapping("/{from}/{to}/{amount}")
    public ResponseEntity<?> transferFunds(@PathVariable("from") int from,@PathVariable("to") int to,@PathVariable("amount") double amount) throws ResourceNotFoundException{
        return accountService.transferFunds(from, to, amount);  
    }
    
    @DeleteMapping("/{accountNumber}")
    public ResponseEntity<?> deleteAccById(@PathVariable ("accountNumber") int accountNumber) throws ResourceNotFoundException{
        String x=accountService.deleteById(accountNumber);
        if(x.equalsIgnoreCase("deleted")){
            return new ResponseEntity<>("deleted successfully",HttpStatus.OK);
        }else {
            throw new ResourceNotFoundException("Account [accountNumber=" accountNumber "] can't be found");
        }
    }
    
    @GetMapping("/balance/{accountNumber}")
    public ResponseEntity<?> getBalanceById(@PathVariable ("accountNumber") int accountNumber) throws ResourceNotFoundException{
        String balance=accountService.getBalanceById(accountNumber);
        
        if(balance.equalsIgnoreCase("Invalid accountNumber")) {
            throw new ResourceNotFoundException("Account [accountNumber=" accountNumber "] can't be found");
            
        }else {
            return new ResponseEntity<>(balance,HttpStatus.OK);
        }
    }
    
    @DeleteMapping("/deleteAll")
    public ResponseEntity<?> deleteAllAccounts(){
        return new ResponseEntity<>(accountService.deleteAllAccounts(),HttpStatus.OK);
    }   

    @PutMapping("/update/{accountNumber}")
    public ResponseEntity<?> UpdateAccount(@PathVariable ("accountNumber") int accountNumber,@RequestBody Account account) throws ResourceNotFoundException{
        Account acc=accountService.updateAccount(accountNumber, account);
        if(acc!=null) {
            return new ResponseEntity<>(acc,HttpStatus.OK);
        }else {
            throw new ResourceNotFoundException("invalid accountNumber and account");
        }
    }
    
    @PutMapping("/deposite/{amount}/{accountNumber}")
    public ResponseEntity<?> deposite(@PathVariable("amount") double amount,@PathVariable("accountNumber") int accountNumber) throws ResourceNotFoundException{
        
        
            return accountService.deposite(amount,accountNumber);
    }
    @PutMapping("/withdraw/{amount}/{accountNumber}")   
    public ResponseEntity<?> withDraw(@PathVariable("amount") double amount,@PathVariable("accountNumber") int accountNumber) throws ResourceNotFoundException{
        return accountService.withdraw(amount,accountNumber);
    }
}
    

我的模型類是(與客戶類有多對一的關系)

    package com.bank.model;
    
    import javax.persistence.CascadeType;
    
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
    
    import org.hibernate.annotations.Proxy;
    
    @Entity
    @Table(name="Account")
    @Proxy(lazy = false)
    public class Account {
    
        @Id
        int accountNumber;
        @Column(name="balance")
        Double balance;
        @Column(name="accountType")
        String accountType;
        
        @ManyToOne( targetEntity=Customer.class,cascade = CascadeType.ALL)
        @JoinColumn(name="ca_fk",referencedColumnName = "customerId")
        Customer customer;
    
        public Account() {
            super();
            
        }
    
        public Account(int accountNumber, Double balance, String accountType, Customer customer) {
            super();
            this.accountNumber = accountNumber;
            this.balance = balance;
            this.accountType = accountType;
            this.customer = customer;
        }
    
        @Override
        public String toString() {
            return "Account [accountNumber="   accountNumber   ", balance="   balance   ", accountType="   accountType
                      ", customer="   customer   "]";
        }
    
        public Integer getAccountNumber() {
            return accountNumber;
        }
    
        public void setAccountNumber(int accountNumber) {
            this.accountNumber = accountNumber;
        }
    
        public Double getBalance() {
            return balance;
        }
    
        public void setBalance(Double balance) {
            this.balance = balance;
        }
    
        public String getAccountType() {
            return accountType;
        }
    
        public void setAccountType(String accountType) {
            this.accountType = accountType;
        }
    
        public Customer getCustomer() {
            return customer;
        }
    
        public void setCustomer(Customer customer) {
            this.customer = customer;
        }
        
        
    }
    

客戶類別

    package com.bank.model;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Table;
    
    import org.hibernate.annotations.Proxy;
    
    @Entity
    @Table(name="Customer")
    @Proxy(lazy = false)
    public class Customer {
    
        @Id
        Integer customerId;
        @Column(name="customerName")
        String customerName;
        
        public Customer() {
            super();
            
        }
    
        public Customer(int customerId, String customerName) {
            super();
            this.customerId = customerId;
            this.customerName = customerName;
        }
    
        @Override
        public String toString() {
            return "Customer [customerId="   customerId   ", customerName="   customerName   "]";
        }
    
        public int getCustomerId() {
            return customerId;
        }
    
        public void setCustomerId(int customerId) {
            this.customerId = customerId;
        }
    
        public String getCustomerName() {
            return customerName;
        }
    
        public void setCustomerName(String customerName) {
            this.customerName = customerName;
        }
        
    }

我收到以下錯誤

    MockHttpServletRequest:
          HTTP Method = POST
          Request URI = /account
           Parameters = {}
              Headers = [Content-Type:"application/json;charset=UTF-8", Accept:"application/json", Content-Length:"114"]
                 Body = {"accountNumber":456,"balance":2000.0,"accountType":"savings","customer":{"customerId":1,"customerName":"Manasa"}}
        Session Attrs = {}
    
    Handler:
                 Type = com.bank.controller.AccountController
               Method = com.bank.controller.AccountController#createAccount(Account)
    
    Async:
        Async started = false
         Async result = null
    
    Resolved Exception:
                 Type = null
    
    ModelAndView:
            View name = null
                 View = null
                Model = null
    
    FlashMap:
           Attributes = null
    
    MockHttpServletResponse:
               Status = 201
        Error message = null
              Headers = [Content-Type:"application/json"]
         Content type = application/json
                 Body = {"accountNumber":456,"balance":2000.0,"accountType":"savings","customer":{"customerId":1,"customerName":"Manasa"}}
        Forwarded URL = null
       Redirected URL = null
              Cookies = []
    2022-03-20 02:11:12.422  WARN 12996 --- [           main] o.s.test.context.TestContextManager      : Caught exception while invoking 'afterTestMethod' callback on TestExecutionListener [org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@485e36bc] for test method [public void com.bank.controller.AccountControllerTest.testbyAccountType() throws java.lang.Exception] and test instance [com.bank.controller.AccountControllerTest@153cfd86]
    
    org.mockito.exceptions.misusing.UnfinishedStubbingException: 
    Unfinished stubbing detected here:
    -> at com.bank.controller.AccountControllerTest.testbyAccountType(AccountControllerTest.java:139)
    
    E.g. thenReturn() may be missing.
    Examples of correct stubbing:
        when(mock.isOk()).thenReturn(true);
        when(mock.isOk()).thenThrow(exception);
        doThrow(exception).when(mock).someVoidMethod();
    Hints:
     1. missing thenReturn()
     2. you are trying to stub a final method, which is not supported
     3. you are stubbing the behaviour of another mock inside before 'thenReturn' instruction is completed
    
        at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:83) ~[spring-boot-test-2.6.4.jar:2.6.4]
        at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:70) ~[spring-boot-test-2.6.4.jar:2.6.4]
        at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.afterTestMethod(ResetMocksTestExecutionListener.java:64) ~[spring-boot-test-2.6.4.jar:2.6.4]
        at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:445) ~[spring-test-5.3.16.jar:5.3.16]
        at org.springframework.test.context.junit.jupiter.SpringExtension.afterEach(SpringExtension.java:206) ~[spring-test-5.3.16.jar:5.3.16]
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAfterEachCallbacks$12(TestMethodTestDescriptor.java:257) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$13(TestMethodTestDescriptor.java:273) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.8.2.jar:1.8.2]
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$14(TestMethodTestDescriptor.java:273) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) ~[na:na]
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAllAfterMethodsOrCallbacks(TestMethodTestDescriptor.java:272) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAfterEachCallbacks(TestMethodTestDescriptor.java:256) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:141) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151) ~[junit-platform-engine-1.8.2.jar:1.8.2]
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.8.2.jar:1.8.2]
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) ~[junit-platform-engine-1.8.2.jar:1.8.2]
        at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) ~[junit-platform-engine-1.8.2.jar:1.8.2]

我的 pom.xml 是

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.bank</groupId>
    <artifactId>capstoneBankProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>capstoneBankProject</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
        <junit.version>4.13.1</junit.version>
    </properties>
    <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<!-- exclude junit 4 -->
 
   
        <exclusion>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </exclusion>
  </exclusions>
</dependency>
<!-- Junit 5 -->
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

我的專案結構

當我運行 Spring Boot 測驗用例時出現錯誤,我無法自行解決

uj5u.com熱心網友回復:

您正在將 mockAccount 投射到一個串列中,而它實際上不是一個串列,這可能就是模擬失敗的原因。

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/450852.html

標籤:弹簧靴 弹簧MVC

上一篇:如何從JavaScript獲取陣列到JavaController?

下一篇:是否可以在不重新調整thymleaf模型的情況下請求控制器

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • CA和證書

    1、在 CentOS7 中使用 gpg 創建 RSA 非對稱密鑰對 gpg --gen-key #Centos上生成公鑰/密鑰對(存放在家目錄.gnupg/) 2、將 CentOS7 匯出的公鑰,拷貝到 CentOS8 中,在 CentOS8 中使用 CentOS7 的公鑰加密一個檔案 gpg -a ......

    uj5u.com 2020-09-10 00:09:53 more
  • Kubernetes K8S之資源控制器Job和CronJob詳解

    Kubernetes的資源控制器Job和CronJob詳解與示例 ......

    uj5u.com 2020-09-10 00:10:45 more
  • VMware下安裝CentOS

    VMware下安裝CentOS 一、軟硬體準備 1 Centos鏡像準備 1.1 CentOS鏡像下載地址 下載地址 1.2 CentOS鏡像下載程序 點擊下載地址進入如下圖的網站,選擇需要下載的版本,這里選擇的是Centos8,點擊如圖所示。 決定選擇Centos8后,選擇想要的鏡像源進行下載,此 ......

    uj5u.com 2020-09-10 00:12:10 more
  • 如何使用Grep命令查找多個字串

    如何使用Grep 命令查找多個字串 大家好,我是良許! 今天向大家介紹一個非常有用的技巧,那就是使用 grep 命令查找多個字串。 簡單介紹一下,grep 命令可以理解為是一個功能強大的命令列工具,可以用它在一個或多個輸入檔案中搜索與正則運算式相匹配的文本,然后再將每個匹配的文本用標準輸出的格式 ......

    uj5u.com 2020-09-10 00:12:28 more
  • git配置http代理

    git配置http代理 經常遇到克隆 github 慢的問題,這里記錄一下幾種配置 git 代理的方法,解決 clone github 過慢。 目錄 git配置代理 git單獨配置github代理 git配置全域代理 配置終端環境變數 git配置代理 主要使用 git config 命令 git單獨 ......

    uj5u.com 2020-09-10 00:12:33 more
  • Linux npm install 裝包時提示Error EACCES permission denied解

    npm install 裝包時提示Error EACCES permission denied解決辦法 ......

    uj5u.com 2020-09-10 00:12:53 more
  • Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包

    Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包。 18 (flaskApi) [root@67 flaskDemo]# yum -y install nginx 19 已加載插件:fastestmirror, langpacks 20 Loading ......

    uj5u.com 2020-09-10 00:13:13 more
  • Linux查看服務器暴力破解ssh IP

    在公網的服務器上經常遇到別人爆破你服務器的22埠,用來挖礦或者干其他嘿嘿嘿的事情~ 這種情況下正確的做法是: 修改默認ssh的22埠 使用設定密鑰登錄或者白名單ip登錄 建議服務器密碼為復雜密碼 創建普通用戶登錄服務器(root權限過大) 建立堡壘機,實作統一管理服務器 統計爆破IP [root ......

    uj5u.com 2020-09-10 00:13:17 more
  • CentOS 7系統常見快捷鍵操作方式

    Linux系統中一些常見的快捷方式,可有效提高操作效率,在某些時刻也能避免操作失誤帶來的問題。 ......

    uj5u.com 2020-09-10 00:13:31 more
  • CentOS 7作業系統目錄結構介紹

    作業系統存在著大量的資料檔案資訊,相應檔案資訊會存在于系統相應目錄中,為了更好的管理資料資訊,會將系統進行一些目錄規劃,不同目錄存放不同的資源。 ......

    uj5u.com 2020-09-10 00:13:35 more
最新发布
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:43:21 more
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:42:36 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:26:53 more
  • 設定Windows主機的瀏覽器為wls2的默認瀏覽器

    這里以Chrome為例。 1. 準備作業 wsl是可以使用Windows主機上安裝的exe程式,出于安全考慮,默認情況下改功能是無法使用。要使用的話,終端需要以管理員權限啟動。 我這里以Windows Terminal為例,介紹如何默認使用管理員權限打開終端,具體操作如下圖所示: 2. 操作 wsl ......

    uj5u.com 2023-04-19 09:25:49 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:19:04 more
  • Linux學習筆記

    IP地址和主機名 IP地址 ifconfig可以用來查詢本機的IP地址,如果不能使用,可以通過install net-tools安裝。 Centos系統下ens33表示主網卡;inet后表示IP地址;lo表示本地回環網卡; 127.0.0.1表示代指本機;0.0.0.0可以用于代指本機,同時在放行設 ......

    uj5u.com 2023-04-18 06:52:01 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:50 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:01 more
  • 你是不是暴露了?

    作者:袁首京 原創文章,轉載時請保留此宣告,并給出原文連接。 如果您是計算機相關從業人員,那么應該經歷不止一次網路安全專項檢查了,你肯定是收到過資訊系統技術檢測報告,要求你加強風險監測,確保你提供的系統服務堅實可靠了。 沒檢測到問題還好,檢測到問題的話,有些處理起來還是挺麻煩的,尤其是線上正在運行的 ......

    uj5u.com 2023-04-05 16:52:56 more
  • 細節拉滿,80 張圖帶你一步一步推演 slab 記憶體池的設計與實作

    1. 前文回顧 在之前的幾篇記憶體管理系列文章中,筆者帶大家從宏觀角度完整地梳理了一遍 Linux 記憶體分配的整個鏈路,本文的主題依然是記憶體分配,這一次我們會從微觀的角度來探秘一下 Linux 內核中用于零散小記憶體塊分配的記憶體池 —— slab 分配器。 在本小節中,筆者還是按照以往的風格先帶大家簡單 ......

    uj5u.com 2023-04-05 16:44:11 more