【问题标题】:react+spring boot development setupreact+spring boot 开发设置
【发布时间】:2019-12-27 20:50:04
【问题描述】:

我正在尝试在开发模式下设置 react 和 spring boot。我运行前端和后端单独的端口,即; http://localhost:3000/api/hellohttp://localhost:8080/api/hello 分别。我喜欢在后端调用服务并在前端显示结果,为此我在 react app package.json 文件中添加了“proxy”:“http://localhost:8080”。但它不起作用。

请帮我解决一下?

package.json 文件

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.3.1",
    "react-dom": "^16.3.1",
    "react-scripts": "1.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:8080",
}

我可以使用前端 reactjs 代码显示后端 spring boot 代码

【问题讨论】:

    标签: reactjs spring-boot


    【解决方案1】:

    您不必定义代理端口。 只需运行您的 Spring Boot 项目,然后从 React 应用程序发送请求

    例如在 React 中:

            fetch("http://localhost:portNumber/login", {
            method: 'POST',
            headers: {'content-type': 'application/json'},
            body: JSON.stringify({
            email: this.state.emailAddress,
            password: this.state.password})
    })
            .then(resopnse => {
        if(response.status === 200){
        }
            })
    

    春季开机:

    @CrossOrigin("*")
    @PostMapping("/login")
    public userLogin(@RequestedBody modalName objectname){
    //Service Call
    } 
    

    【讨论】:

      猜你喜欢
      • 2016-11-03
      • 1970-01-01
      • 2019-03-29
      • 1970-01-01
      • 2019-01-28
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 2015-10-29
      相关资源
      最近更新 更多