英文:
After deployed the App in Elastic Beanstalk end point of app throws 404 not found in SpringBoot+MySql+Angular app with maven
问题
这实际上是我第一次在AWS上部署,而且自己做这个任务更加困难。
在Elastic Bean中创建了我的应用程序以及其相应的带有实例的RDS数据库之后,我在Spring Boot应用程序中创建了一个快照(jar),这也是AWS应用程序部署过程中的一部分。
还在其软件类别中配置了一些项目,涉及RDS数据库端点、服务器端口、数据库用户名等等...。
然后在完成了所有这些过程后,将应用程序部署到了一个URL上。
但是当我使用我的Spring Boot控制器所拥有的端点来访问该URL时,我收到一个404 Not Found的错误;但是如果我决定在本地工作,仅请求Elastic Bean中应用程序创建的RDS数据库,端点就会显示数据,应用程序也能正常工作。
在我的Spring Boot应用程序中,我在应用程序的属性中声明了与AWS中的数据库的连接。
spring.datasource.url=jdbc:mysql://aat54g98qswmf3.clnhc7kmwszz.us-west-2.rds.amazonaws.com:3306/ebdb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=xxxx
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
logging.level.org.hibernate.SQL=debug
因此,在本地工作的Spring控制器没有任何问题。
@RequestMapping(path = "/restaurant-booking/version1")
public class RestaurantController {
@Autowired
RestaurantService restaurantService;
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/restaurant/all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
// 一些代码...
};
然后在我的浏览器中:
但是如果我切换到在AWS上部署的EB应用程序提供的URL,并使用相同的端点:
任何帮助都将是极好的,因为老实说,我找不到问题出在哪里或者应该从哪里入手!提前感谢!!
英文:
is literally my first time on AWS deployments , and doing it by myself is harder the task.
After having created my app in Elastic Beans and its respective RDS database with its instance , i created a Snapshot (jar) on my Springboot app which was also implemented in the deployment process of the AWS application.
Also several items were configured in its Software Category referring the RDS database endpoint, server ports, user-name of database , etc...
.
Then after all that process , got the app deployed with a url.
But when i apply that url with the endpoints my springboot controllers have , i receive as error a 404 Not Found; but if i decide to work on local requesting only the RDS database created by the application in Elastic Bean the endpoints shows data and the app works
Literally on my Spring Boot App i declared in the app. properties the connection to that database in AWS
spring.datasource.url=jdbc:mysql://aat54g98qswmf3.clnhc7kmwszz.us-west-2.rds.amazonaws.com:3306/ebdb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=xxxx
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
logging.level.org.hibernate.SQL=debug
thus my controllers in the spring working in local don't have any problem
@RequestMapping(path = "/restaurant-booking/version1")
public class RestaurantController {
@Autowired
RestaurantService restaurantService;
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/restaurant/all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
some code.........
};
But if i switch to the url facilitated by the deployed EB app in AWS, and the use the same endpoint
Any help guys would be amazing , cause honestly can't find the problem or where to look at!
Thanks in advance!!!
答案1
得分: 1
白标签错误页面是 Spring 中的默认错误页面,当您没有定义自己的错误页面时会出现。这意味着您的应用已部署并正在运行。您可能搞错了请求映射或者 URL。
如果我们查看您的映射,我们可以看到 URL 应该是.../restaurant-booking/version1/restaurant/all
请求映射在类和方法级别上嵌套。
实际上,在本地您使用了正确的 URL,但在部署的版本中没有。
英文:
The whitelabel error page is the default error page in spring when you have not defined your own. This means your application is deployed and running. You either messed up your request mapping or your url.
If we look at your mappings we see the url should be .../restaurant-booking/version1/restaurant/all
Request mappings get nested when they are on the class and method level.
You actually used the correct url locally but not on your deployed version.
答案2
得分: 0
问题可能是由于与RDS的连接以及Spring Boot应用程序的正确环境配置之间的连接问题引起的。
我建议在继续创建环境之前(甚至之后),确保正确连接RDS。有关配置部分:您可以使用application-prod.properties文件,为软件配置指定一个环境变量和值,标记为SPRING_PROFILES_ACTIVE,并将其值设置为prod。
application-prod属性包括:
server.port=5000
spring.datasource.url=jdbc:mysql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
spring.datasource.username=${RDS_USERNAME}
spring.datasource.password=${RDS_PASSWORD}
spring.jpa.hibernate.ddl-auto=create
在创建环境之前或之后选择适当的RDS。
您需要为包含RDS的安全组配置入站和出站规则,以允许进行创建、删除、更新等操作。
然后最后在环境中上传jar文件。对我有用。
英文:
The problem might be arising due to the connectivity with the RDS and the correct Environment configuration for your Spring Boot Application.
I would suggest that prior to continuing with the environment creation (or even after), make sure you connect the RDS properly. For the configuration part:-
you can make use of application-prod.properties file and specify an environment variable and value for software configuration labelled SPRING_PROFILES_ACTIVE and set its value to prod.
The application-prod properties consist of:-
server.port=5000
spring.datasource.url=jdbc:mysql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
spring.datasource.username=${RDS_USERNAME}
spring.datasource.password=${RDS_PASSWORD}
spring.jpa.hibernate.ddl-auto=create
Select a suitable RDS before or after creating the environment.
You need to configure the inbound and outbound rules for security group encompassing the RDS manually to allow access for creating, delete, update, etc.
And then finally upload the jar file in the environment. Worked for me.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论