Spring support for Maven2 WebApps - spring-mvc

I can create a minimal web application by using the maven-archetype-webapp .
Now I want to make my webapp Spring-Web-MVC powered.
Can I directly modify my POM, and how?
What's the best practices for the folder structure, and so on?
Can you show me a spring web mvc archetype, or a hello world example?

The STS (Spring Source Tool Suite) ships with the Spring Template Project, this project wizard will create a simple Spring MVC webapp + maven support.
Hope this helps
You can refer the step-by-step instructions, under the below link.
http://webapptutorials.wordpress.com/category/spring-mvc/

Maven Overlays document describes in great detail how web application should be structured using Maven. Here you'll find my simple Spring MVC showcase (REST-oriented).
Of course you are allowed to modify pom.xml (if the file is so complicated that users are afraid to modify it, then there must be something wrong with Maven...)
The only Spring-specific convention is to place general applicationContext.xml file under /WEB-INF - but this can be easily overridden.

You may also want to look using appfuse to bootstrap your spring-mvc application.

Related

Create Controller and add Views to another project

Visual Studio 2015 + all updates.
Asp .Net Web application (MVC).
I start off by adding a few class libraries and separating the Asp .Net WA into layers i.e. DataAccess, Business Logic and the web project itself.
Once separated I add relevant references and everything is working as I expect it to be (i.e. the application functions as it did before I separated it into layers).
In my BL (Controllers are found here). I don't have the option to Add a Controller, like you would when right clicking the Controllers folder in the default project, so add the below line
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
to the csproj file for my class library and the Add Controller option now appears. Create a controller but throws an error which was due to not having a web.config file - add this file and all works (although it would be nice to have this library working without a web.config file).
The problem I've hit is, when the Controller is created it also adds a View template within the class library but my Views folder is located in my web project.
Have I done this wrong? Is there a workaround so when a controller is created, it also creates the Views into the correct project? Or another approach for this?
This is just a guess, but it seems like you are try to use a UI-based architectural pattern to build your business layer.
Typically, your models, views, and controllers are all maintained in the main web-app project. Any supporting functions (like your BL and DL) are added via class libraries. The Visual Studio MVC templates are built around that concept, which is why you had to manually add support with the GUID - and why it automatically creates the view.
If I may ask, why are you trying to build controllers into your BL? If you are trying to decouple your UI from your server code, perhaps WebAPI would be a better option.
UPDATE - A few helpful links
ProDinner - ASP.NET MVC Sample App
N Layered App with Entity Framework, Autofac, ASP.NET MVC and Unit Testing
Architecture Guide: ASP.NET MVC Framework + N-tier + Entity Framework and Many More
Most of your issues boil down to using the scaffold. The scaffold is great when you're just starting out or for extremely simple projects, but it quickly falls down beyond that. Specifically, adding a controller via scaffold is designed for an MVC project, so it expects to find things you'd find in an MVC project. Additionally, it creates scaffolded views in an appropriate directory in Views because, again, that's what it's designed to do.
The simplest solution, then, is to just not use the scaffolds. A controller is just a class that inherits from Controller. Nothing special there. Then, you can create the views where you want to create them.

Spring MVC and user defined themes

I'm working on creating a small Spring MVC app would like to implement some form of theme-ing. I've got experience with using Sitemesh and Tiles but never had any experience in creating a theme-able app before.
I would like to do it in such a way that end users can create there own designs and put them somewhere where the application can load from and use.
I'm not sure what the best mechanism or technologies are for this. I've been thinking of Velocity or Freemarker but have no idea how to approach this solution.
I would like to make the app a war and deploy to Tomcat.

Minimal mvc references from nuget in Web Api project

Got a clean Web api project where I want to put my Rest services.
Lets say I would like to reference System.Web.Mvc. Trying to add it through Nuget seems to give a LOT of other references. For example Razor!
Does it exist any minimal mvc Nuget package?
I recommend Web API empty template extension. It basically provides only the structure.
There is also a tutorial on code project.
Here is an image of generated project (taken from code project):
I've used this extension and it fits quite well into my needs (rest services as an API, and no UI pages).

Spring MVC Portlet Eclipse plugin

I am stuck with it. please anyone know about simple portal/portlet plugin for eclipse. please let me know with detail description. because i want to make portlet by using Spring MVC. I DON'T WANT TO USE LIFERAY!!!!
I suggest you to install Spring Source Tool Suite.
It is just another eclipse but with all the Spring framework related plugins preloaded in it.
I think it would be easier for you to create spring portlet using it.
Hope this helps you.
Cheers.
You may take a look in the book "Portlets in Action", Ashish Sarin.
You will get everything you need to know about portlets and Spring MVC. Personally, it helped me a lot.
If you want use spring mvc into liferay portlets yo should:
Create a maven portlet with liferay archetype.
in the pom.xml add all libraries for spring, portlet and liferay.
config your portlet creating, web.xml, applicationContext.xml, and portlet.xml
Write your code.

What is the best way to implement a plugin architecture for asp.net webforms application?

We have a 3-tier web application written in ASP.Net Webforms where we will not be able to port it - recession really sucks! - to MVC. Our goal is to implement a plugin architecture. One way would be to use the App_Code folder. Are there any better alternatives?
My plugin architecture is developed in a completely separate solution. I include a reference to the libraries in my web project. I use a plugin manager that runs in Application_Start and loads the plugin configuration from the web.config file. The configuration specifies the full name of the actual plugin being used and uses Activator.CreateInstance to instantiate the plugin. All plugins implement an IPlugin interface as well as an interface for each specific type of plugin.
Make a plugin-loader assembly maybe? :)
Avoid business-level code in ASP.NET applications. Try to keep it as "presentation only"-alike as you can..

Resources