在与 localhost 不同的域中查询 Web 项目中的 mysql 数据库未检索到任何数据

Querying a mysql database in a web project throughout a different domain than localhost retrieves no data

试图理解为什么会发生这种情况。当我查询我在主机文件上设置的不同域时,就像没有检索数据库中的数据一样。我有一个包含 angular、spring-boot 和 mysql 的个人项目。 Angular 查询由正在查询 mysql 的 Spring 公开的 API。当我 运行 项目并转到 URL localhost:8080 时,我得到了所有信息,但是当我转到 mysite.com:8080 时,似乎所有数据都来自 mysql 未检索到。

我这样修改了文件hosts

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1             localhost 

127.0.0.1 myownproject.com

并且我将 mysql 上的所有权限授予用户@mysite.com

的数据库 mydb

这是我的spring数据库配置

#override the spring parameter 'create-drop', 'create' creates the schema deleting the previous data
spring.jpa.hibernate.ddl-auto=create-drop

spring.jpa.show-sql=true
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.database=H2

database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/expediente_electronico
database.username=user
database.password=user

谢谢

我终于可以解决这个问题了。我 post 以防万一的答案对其他人有用。

在前端(在 angular 中)我有具有 url

的 http 请求
http://localhost:8080/restservice

我将此 angular 请求更改为此 url

http://myownproject.com:8080/restservice

只是工作正常(显然停止工作之前的 URL)。我不确定,但我可以想象这是因为 Spring 允许在浏览器中请求给定的 URL,但是当 Angular 试图请求不同的 URL 不允许,这就是数据未检索到的原因。