简体   繁体   English

将框架用于简单的Java Web应用程序是否有意义?

[英]Does it make sense to use a framework for a simple java web app?

I've done lots of java web development using jsps and servlets, and I have found this approach to be straightforward and flexible. 我使用jsps和servlet做了很多java web开发,我发现这种方法简单灵活。 Some of the groundwork involved though - such as managing database connections - is rather tedious, and it takes a fair amount of work just to get a new web app off the ground. 然而,涉及的一些基础工作 - 例如管理数据库连接 - 相当繁琐,只需要开展新的Web应用程序就需要花费大量的工作。

I'm therefore considering using a framework for the first time, but my impression of frameworks is that they're mostly used for large J2EE applications and involve a lot of complex configuration. 我正在考虑第一次使用框架,但我对框架的印象是它们主要用于大型J2EE应用程序并涉及许多复杂的配置。 What I'm looking for is something simple that (after the initial learning curve) will enable me to get up and running with a new web app as quickly as possible. 我正在寻找的是一些简单的东西(在初始学习曲线之后)将使我能够尽快启动并运行新的Web应用程序。

So my question is - does it make sense to use a framework for a simple java web app? 所以我的问题是 - 使用一个简单的Java Web应用程序的框架是否有意义?

Note that I'm not asking which framework to use (if indeed a framework is recommended), as it has already been asked here . 请注意,我不是要问使用哪个框架(如果确实建议使用框架),因为这里已经提到

如果你不使用网络框架,你通常最终会写一个 - 很糟糕。

Yes, I would use a web framework for the following reasons: 是的,我会使用Web框架,原因如下:

  1. Increased navigation capabilities and controls. 增加导航功能和控制。 Even though you may not need them, they are there for you to use should you require them at any time 即使您可能不需要它们,如果您在任何时候需要它们,它们也可供您使用
  2. As others have indicated, apps grow over time and you will feel the need for the framework at some point in time in the future. 正如其他人所指出的,应用程序随着时间的推移而增长,您将在未来的某个时间点感受到框架的需求。 When you need to add additional pages and navigation 当您需要添加其他页面和导航时
  3. Features that allow you to plug into other frameworks such as security and DB access frameworks. 允许您插入其他框架(如安全性和数据库访问框架)的功能。 Spring is a prime example in the Java world. Spring是Java世界的一个典型例子。 You never have to use Spring but it plugs in so well with Struts, Spring MVC, Hibernate, Acegi etc. It ends up saving you the hassle of doing all of the plumbing on your own. 你永远不必使用Spring,但它可以很好地插入Struts,Spring MVC,Hibernate,Acegi等。最终可以省去你自己完成所有管道工作的麻烦。
  4. Support!!! 支持!!! Good frameworks almost always have a vibrant community to support them and ask and answer questions. 良好的框架几乎总是有一个充满活力的社区来支持他们并提出并回答问题。

It may seem like too much hassle initially but definitely saves you much time in the future 这看起来似乎太麻烦了,但绝对可以为你节省很多时间

It makes a lot of sense. 这很有道理。 My team has spent the better part of five years with our open source stack and no matter and we have a "seed" project (works like appfuse) that we use to create all new web apps. 我的团队用我们的开源堆栈度过了五年的大部分时间,无论如何我们都有一个“种子”项目(就像appfuse一样),我们用它来创建所有新的Web应用程序。 Even the simple two pagers from the pov of maintaining the app, it looks like every other app, just smaller. 即使是维护应用程序的简单两个寻呼机,它看起来像其他应用程序,只是更小。

The short is you won't get any return on the investment right now, but you will as the project evolves and you maintain it. 简而言之,您现在不会获得任何投资回报,但随着项目的发展和维护,您将获得回报。

I'd say it actually matters quite a lot which framework you go for. 我说它实际上对你要采用的框架非常重要。 Something like Spring MVC is fairly unobtrusive in your code and allows you existing stuff to run quite a lot as-is. 像Spring MVC这样的东西在你的代码中相当不引人注目,并允许你现有的东西按原样运行。 Other frameworks have much more specific ideas about how you should do things. 其他框架对于如何做事情有更具体的想法。

Yes it does make sense. 是的,它确实有意义。 Apps can grow and change and might require something a framework can provide easily in the future. 应用程序可以增长和变化,并且可能需要框架可以在将来轻松提供的内容。

For example at my workplace we have simple jsp / servlet app. 例如,在我的工作场所,我们有简单的jsp / servlet应用程序。 It needs to be rewritten just because of what I explained above. 它只是因为我上面解释的内容而需要重写。 If someone would have taken the time to just get the framework setup we would be in better shape today. 如果有人花时间来完成框架设置,我们今天会更好。

Yes it makes sense. 是的,这是有道理的。 However implicit in your question is that the wrong (for you) framework can be more pain than it's worth - and that's true. 然而,你的问题隐含的是错误的(对你而言)框架可能比它的价值更加痛苦 - 这是真的。 There is a world of difference between some heavy J2EE framework and something light and cheerful like grails. 在一些繁重的J2EE框架和像grails一样轻松愉快的东西之间存在着天壤之别。

What's the alternative? 有什么选择? Rolling your own? 滚动你自己? Embedding all the navigation and logic in the JSPs? 在JSP中嵌入所有导航和逻辑?

I agree with those who say that a web framework is worth it. 我同意那些说Web框架值得的人。 There are literally hundreds now (eg, Struts, JSF, Spring, Wicket, etc.). 现在有几百个(例如,Struts,JSF,Spring,Wicket等)。 Pick one that suits you. 选择一个适合你的。

There are two kinds of applications: 有两种应用:

1) the kind that you throw away and never use again, and therefore should not worry about modularity, maintainability and clarity. 1)你扔掉但永不再使用的那种,因此不应该担心模块化,可维护性和清晰度。

2) the real kind. 2)真实的那种。

It may sometimes seem that your app may never have to grow, scale, or service a larger feature set / user base than you currently are planning for....I assure you, that perception is always wrong. 有时您的应用程序可能永远不会需要增长,扩展或维护比您当前计划的更大的功能集/用户群....我向您保证,这种看法总是错误的。

Frameworks, specifically things like Struts for MVC in Java, Spring for MVC and Dependency Injection, Hibernate for Object-Relational Modeling are all extremely valuable tools that lead to modularity, maintainability and clarity in your code. 框架,特别是像Java中的Struts for MVC,Spring for MVC和依赖注入,Hibernate for Object-Relational Modeling等都是非常有价值的工具,可以在代码中实现模块化,可维护性和清晰度。 So, to answer your original question.... Yes, emphatically. 所以,回答你原来的问题......是的,强调。

No it doesn't unless: 不,除非:

  1. you don't have any java experience in your team 您的团队中没有任何Java经验
  2. you are doing just a prototype that must be ready in hours 你正在做一个必须在几小时内准备好的原型
  3. you don't trust your developers enough to let them write your application 你不相信你的开发人员足以让他们编写你的应用程序
  4. you don't plan to let your developers learn and improve 你不打算让你的开发人员学习和改进

Danger in using frameworks include but not limited to: 使用框架的危险包括但不限于:

  1. you'll get all framework defects on top on your own 您将自己获得所有框架缺陷
  2. you'll be unable to do realistic estimates until you know perfectly the framework 在你完全了解框架之前,你将无法做出真实的估计
  3. your team won't learn how to program a web server 您的团队将不会学习如何编写Web服务器
  4. you'll find your team passing more and more time on google instead that solving problems by writing code. 你会发现你的团队在谷歌上传递的时间越来越多,而不是通过编写代码来解决问题。

The only thing that is worst that choosing a open source framework is having a separate R&D team in the company who should create the "big complete ultimate company framework". 选择开源框架唯一最糟糕的事情就是在公司中建立一个独立的研发团队,他们应该创建“完整的最终公司框架”。

but my impression of frameworks is that they're mostly used for large J2EE applications and involve a lot of complex configuration 但我对框架的印象是它们主要用于大型J2EE应用程序并涉及许多复杂的配置

Not necessarily true. 不一定是真的。 The good frameworks are built to scale well so that they will take you from small apps to very large apps. 良好的框架可以很好地扩展,以便它们可以将您从小型应用程序带到非常大的应用程序。 Many of the frameworks today are moving towards zero configuration so you will find them easier and easier to use. 今天的许多框架都朝着零配置方向发展,因此您会发现它们更容易使用。

You are right that it does take an initial effort to learn the framework itself but that investment pays for itself in the very first application you build. 你是对的,它确实需要最初的努力才能学习框架本身,但这种投资会在你构建的第一个应用程序中为自己付出代价。 And meta frameworks like AppFuse makes it even easier to get started since it pre-configures the frameworks for you. AppFuse这样的元框架使它更容易上手,因为它为您预先配置了框架。

Frameworks make sense for most applications. 框架对大多数应用程序都有意义。 It may be necessary for you to build your own or adopt some other framework. 您可能需要构建自己的或采用其他框架。 The most important questions is the granularity of your data structures. 最重要的问题是数据结构的粒度。 What I mean by this is do you need to just enter data or do you need to parse, compile and execute dynamic code? 我的意思是你需要输入数据还是需要解析,编译和执行动态代码?

If you think of a frame works as a gauge and to the left is an all ready existing frame work open source or closed and to the right is all custom framework then super impose your code on top of that frame work where the level of complexity increases to the right. 如果你认为一个框架作为衡量标准,左边是一个现成的现有框架工作开源或关闭,右边是所有自定义框架然后超级强加你的代码在该框架工作的顶部复杂程度增加在右边。 The farther right you go the more of a stuggle you will have with the frame work (IMO). 你走得越远,你就会对框架工作(IMO)产生更大的影响。

However, you can also slowly migrate from existing to custom framework. 但是,您也可以从现有框架缓慢迁移到自定义框架。

There is also the question about your business. 还有关于您的业务的问题。 If you work for a business that does not look at software as it's core compentency such as a bank or hospital then you need to way that into how much of a frame work you want to build. 如果您为一家不看软件的企业工作,因为它是核心的能力,例如银行或医院,那么您需要了解您想要构建多少框架工作。

Bottom line a framework of some type will always be useful. 底线一些类型的框架总是有用的。

Using a framework may add some overhead to your web-app development due to the learning curve. 由于学习曲线的原因,使用框架可能会为您的Web应用程序开发增加一些开销。 However, depending on the framework you choose, you may be able to realize the following benefits: 但是,根据您选择的框架,您可能会实现以下好处:

  1. Scalability 可扩展性
  2. Maintainability 可维护性
  3. Clear Division of your model (eg MVC) 明确划分您的模型(例如MVC)
  4. Out-of-the-box components(SessionManagement,authentication,etc ) 开箱即用的组件(SessionManagement,身份验证等)
  5. Third party plugins 第三方插件
  6. Modularity inherited from the framework 模块化继承自框架
  7. Many others. 很多其他的。

Besides, the learning curve is a variable factor. 此外,学习曲线是一个可变因素。 Some frameworks may be easier to learn than others depending on your skills. 根据您的技能,某些框架可能比其他框架更容易学习。

It definitely makes sense to look into using a framework even if for no other reason than it'll give you a new area of knowledge. 考虑使用框架,即使没有其他原因,它也会给你一个新的知识领域。 If you've got the time to invest in learning a framework then you may well find in time that it's easier and faster to use that for new projects no matter how simple they are. 如果您有时间投资学习框架,那么您可能会及时发现,无论它们多么简单,都可以更轻松,更快速地将其用于新项目。

Also, if I could vote for SamBeran's post then I would. 另外,如果我可以投票给SamBeran的帖子那么我会。 Getting started with a framework will involve several moments of "oh great! I don't need to write all that boilerplate again!". 开始使用框架将涉及几个时刻“哦,太棒了!我不需要再次编写所有样板了!”。

I'd say use one - like you said, it's rather tedious to get stuff up and running for even a simple java web app. 我会说使用一个 - 就像你说的那样,即使是一个简单的java网络应用程序也能让你的东西运行起来相当繁琐。 If the framework helps you get the job done faster and provides the services you need, I'd say it makes sense. 如果框架可以帮助您更快地完成工作并提供您需要的服务,那么我认为它是有道理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM