Spring + Hibernate + Angular + Maven + Tomcat项目文件夹结构问题 [英] Spring + Hibernate + Angular + Maven + Tomcat Project folder structure issues

查看:254
本文介绍了Spring + Hibernate + Angular + Maven + Tomcat项目文件夹结构问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我一直在努力整理。我的老板给了我一个新的任务:拿这个模板: https://github.com/DavidKk/ngAdmin

我看了一下Spring,使用了Spring Initializr: https://start.spring.io/ 做一个基本的项目,使用jar命令工具创建一个WAR文件,在tomcat上部署它,并且它工作d。我已经使用了这两个,因为IntelliJ Commuity没有实现这些功能,除非您支付Ultimate版本。



我看了一下这个CRUD示例: http ://www.concretepage.com/spring-4/spring-mvc-4-rest-angularjs-hibernate-4-integration-crud-tutorial-with-ngresource-example ,并使其工作,并理解Spring如何使用依赖注入,Hibernate如何将对象保存到数据库中,以及AngularJS如何提供我的客户请求的单页布局。



现在,我的问题是,这个模板有一个完全不同的目录结构,如果我移动文件什么都不会起作用。从头开始不是一种选择,我们采用前端模板,稍微修改它,开发客户端和服务器的后端工具。我不明白的是,我如何能够在Spring中使用它,它有着完全不同的目录结构,或者与Tomcat一样,它也期望不同的东西,或者它会给我一个404的空间。从我所看到的,这个项目有是用Grunt构建的,所以我不知道是否有任何方法可以从Grunt转到Maven,并且仍然有效。我真的不知道该怎么做,而且我必须在本周末之前完成。任何帮助,将不胜感激,谢谢。

解决方案

您显示的模板仅用于前端。 b
$ b

使用spring初始化器创建一个项目。



您将拥有{目录} / src / main / java和其他东西。
创建{directory} / client /
放入ngAdmin的东西。



ngAdmin使用grunt构建客户端,并在目录目录。这将是{directory} / client / dest /



配置maven-frontend-plugin以安装js stuff并在使用maven构建时运行grunt。
$ b

添加maven-resource-plugin配置从{directory} / client / dest /复制到$ {project.build.directory} / client

配置maven war插件包含这个目录

 < plugin> 
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-war-plugin< / artifactId>
<配置>
< attachClasses> true< / attachClasses>
< webResources>
< resource>
< directory> $ {project.build.directory} / client< / directory>
< / resource>
< / webResources>
< / configuration>
< / plugin>

这样,当你构建战争时,客户端应该在其中(解压缩战争并检查)

然后你将有一些配置可以告诉spring-mvc在哪里可以找到这些,但我手边没有。



希望得到这个帮助。

Okay, so I have been trying all day to sort this out. My boss has assigned me a new task: Take this template: https://github.com/DavidKk/ngAdmin , figure out how AngularJS works, figure out how Spring works, how does Hibernate work, how does Maven work for project builds, tests etc, implement a basic CRUD example inside that template on a MySQL database, deploy on Tomcat.

So, first, this is a lot of stuff all at once, stuff that I have not ever worked with, maybe with Hibernate and a bit with JPA, and he wants all this stuff sorted out by the end of the week, when we will talk more about the project with the client, so we can tell him what approach we will take on the development process.

I took a look at Spring, used Spring Initializr: https://start.spring.io/ to make a basic project, used the jar command tool to make a WAR file, deployed it on tomcat, and it worked. I have used these two, because IntelliJ Commuity has none of these implemented, unless you pay for the Ultimate edition.

I took a look at this CRUD example: http://www.concretepage.com/spring-4/spring-mvc-4-rest-angularjs-hibernate-4-integration-crud-tutorial-with-ngresource-example , and made it work, and understood how Spring uses dependency injection, how Hibernate persists objects into the database, and how AngularJS provides the single-page layout that my client has asked for.

Now, my problem is, this template has a whole different directory structure, and if I move files around nothing is going to work. Starting everything from scratch is not an option, we take a front end template, modify it a little bit, develop the back-end stuff for client and server. What I do not understand is how I could ever use this with Spring, which has a whole different directory structure, or with Tomcat, which expects different stuff too, or it will throw me a 404. From what I have seen, this project has been built with Grunt, so I do not know if there is any way to go from Grunt to Maven, and have it still work. I don't really know what to do, and I must finish this by the end of the week. Any help would be appreciated, thanks.

解决方案

The template you show is only for the front-end.

Create a project with spring initializer.

You'll have {directory}/src/main/java and other stuff. Create {directory}/client/ Put the ngAdmin stuff in it.

ngAdmin uses grunt to build the client, and generate the site in the dest directory. This will be {directory}/client/dest/

Configure maven-frontend-plugin to install js stuff and run grunt when building with maven.

Add maven-resource-plugin configuration to copy from {directory}/client/dest/ to ${project.build.directory}/client

Configure maven war plugin to include this directory

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <attachClasses>true</attachClasses>
        <webResources>
            <resource>
                <directory>${project.build.directory}/client</directory>
            </resource>
        </webResources>
    </configuration>
</plugin>

This way, when you build the war, the client should be in it (unzip the war and check)

Then you will have some config to tell spring-mvc where exactly to find those, but I don't have that on hand.

Hope this help.

这篇关于Spring + Hibernate + Angular + Maven + Tomcat项目文件夹结构问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆