Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 581
  • Last Modified:

spring resources

Hi,

I was going through below links
http://www.mkyong.com/featured/top-20-java-websites/

I was looking specfically for spring framework related links with simple explanation, working examples with screenshots etc.

Please advise

 Any links resources ideas highly appreciated. Thanks in advance
0
gudii9
Asked:
gudii9
2 Solutions
 
Ken ButtersCommented:
This tutorial has getting started with a "Hello Spring" example.

http://www.tutorialspoint.com/spring/spring_hello_world_example.htm
0
 
chaitu chaituCommented:
you also check mkyong spring tutorials.it is clearly explained with maven scripts.

http://www.mkyong.com/tutorials/spring-tutorials/
0
 
gudii9Author Commented:
1. Generate project structure with Maven

In command prompt, issue following Maven command :

mvn archetype:generate -DgroupId=com.mkyong.common -DartifactId=SpringExamples
      -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Maven will generate all the Java’s standard folders structure for you (besides resources folder, which you need to create it manually)
2. Convert to Eclipse project

Type “mvn eclipse:eclipse” to convert the newly generated Maven style project to Eclipse’s style project.

mvn eclipse:eclipse

Later, import the converted project into Eclipse IDE.
Create a resources folder
Create a resources “/src/main/resources” folder, the Spring’s bean xml configuration file will put here later. Maven will treat all files under this “resources” folder as resources files, and copy it to output classes automatically.
3. Add Spring dependency

Add Spring dependency in Maven’s pom.xml file.

File : pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
      http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.mkyong.common</groupId>
      <artifactId>SpringExamples</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>SpringExamples</name>
      <url>http://maven.apache.org</url>
      <dependencies>
 
            <!-- Spring framework -->
            <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring</artifactId>
                  <version>2.5.6</version>
            </dependency>
 
      </dependencies>
</project>

Issue “mvn eclipse:eclipse” again, Maven will download the Spring dependency libraries automatically and put it into your Maven’s local repository. At the same time, Maven will add the downloaded libraries into Eclipse “.classpath” for dependency purpose.
4. Spring bean (Java class)

Create a normal Java class (HelloWorld.java) at “src/main/java/com/mkyong/common/HelloWorld.java”. Spring’s bean is just a normal Java class, and declare in Spring bean configuration file later.

In that mkyong link step1, step2, step3 then importing project to eclipse is not clear , detailed to me.

I created one folder under C drive called gpprojects

gave command

mvn archetype:generate -DgroupId=com.mkyong.common -DartifactId=SpringExamples
      -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false


I got message like Success etc.


then in the same location from command prompt i gave command

mvn eclipse:eclipse

I got error saying build failute.

Is there is a way you can send me some screenshots on how to d these steps. Please advise
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
What was the error message?
0
 
Ken ButtersCommented:
I followed what you did.

Ended up with this error.
[INFO] ------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-eclipse-plugin:2.9:eclipse (default-cli): Goal requires a project to execute but there is no POM in this directory

The reason for the error is that the "mvn eclipse:eclipse" command must be executed from the newly created project folder called SpringExamples...

So you need to change directory to here and issue this command:
..\gpprojects\SpringExamples>mvn eclipse:eclipse

Open in new window

0
 
gudii9Author Commented:
Now step 1, step 2 worked(for step 2 i have to move to newly generated SpringExamples folder)

mvn archetype:generate -DgroupId=com.mkyong.common -DartifactId=SpringExamples -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

mvn eclipse:eclipse


What is difference between above two commands. It is same set of commands i have to use for any spring maven project?


Later, import the converted project into Eclipse IDE.

How to import to eclipse(import as regular project or import and maven project?)
please advise
0
 
gudii9Author Commented:
Create an xml file (Spring-Module.xml) at “src/main/resources/Spring-Module.xml“. This is the Spring’s bean configuration file, which declares all the available Spring beans.

File : Spring-Module.xml

<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
      <bean id="helloBean" class="com.mkyong.common.HelloWorld">
            <property name="name" value="Mkyong" />
      </bean>
 
</beans>


I do not see src/main/resource package/folder(what is the differnece between package and folder in this case?) to put the xml file
0
 
Ken ButtersCommented:
What is difference between above two commands. It is same set of commands i have to use for any spring maven project?

mvn archetype:generate -DgroupId=com.mkyong.common -DartifactId=SpringExamples -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

This first command sets up the example spring project.  Note the -DgroupId=com.mkyong.common etc...   it creates the necessary folder structures and downloads the examples to your local machine.

mvn eclipse:eclipse converts the SpringExamples project to an "Eclipse Project".

How to import to eclipse(import as regular project or import and maven project?)
please advise

To import into eclipse...

Open Eclipse ... goto File / Import

And Select "Existing Projects Into Workspace"

Then navigate to and select the "SpringExamples" folder.
0
 
gudii9Author Commented:
when i ran App.java i see output as below

Feb 27, 2014 11:24:43 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c24ae7: display name [org.springframework.context.support.ClassPathXmlApplicationContext@c24ae7]; startup date [Thu Feb 27 23:24:42 EST 2014]; root of context hierarchy
Feb 27, 2014 11:24:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Spring-Module.xml]
Feb 27, 2014 11:24:45 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@c24ae7]: org.springframework.beans.factory.support.DefaultListableBeanFactory@17412d0
Feb 27, 2014 11:24:45 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@17412d0: defining beans [helloBean]; root of factory hierarchy
Hello ! Mkyong



While importing as maven project i see couple of errors as attached. Can you please advise what they are. I just ignored one of them and other one fixed when i right click and say QuickFix(what this QuickFix does internally?)
please advise
ImportMavenProj.jpg
ImportMavenProj2.jpg
ImportMavenProj3.jpg
ImportMavenProj4.jpg
ImportMavenProj5.jpg
0
 
gudii9Author Commented:
And Select "Existing Projects Into Workspace"

How is above different from

file--->import--->maven--->existing maven project into eclipse(as attached in above post screenshots)

Basically how importing as regular project different from maven project. please advise
0
 
Ken ButtersCommented:
If you import as a maven project, then an eclipse plugin will try to convert the maven project to an eclipse project during the import process.

The tutorial you were following mentioned using mvn eclipse:eclipse to convert the maven project to an eclipse project.

Since you already had converted it to an eclipse project using mvn eclipse:eclipse... it should work to just import "existing (Eclipse Project) into Workspace.

By importing as a maven project... you were converting it from an maven project to an eclipse project during that import process.
0
 
gudii9Author Commented:
By importing as a maven project... you were converting it from an maven project to an eclipse project during that import process.

Does it corrupt or mess if i do

mvn eclipse:eclipse

also

import as a maven project(even though above step converted the maven project to an eclipse project and i am trying to do again)

Please advise
0
 
Ken ButtersCommented:
No it shouldn't mess anything up.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now