Solved

spring resources

Posted on 2014-02-25
13
511 Views
Last Modified: 2014-02-27
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
Comment
Question by:gudii9
13 Comments
 
LVL 19

Accepted Solution

by:
Ken Butters earned 350 total points
ID: 39887016
This tutorial has getting started with a "Hello Spring" example.

http://www.tutorialspoint.com/spring/spring_hello_world_example.htm
0
 
LVL 20

Assisted Solution

by:chaitu chaitu
chaitu chaitu earned 150 total points
ID: 39891184
you also check mkyong spring tutorials.it is clearly explained with maven scripts.

http://www.mkyong.com/tutorials/spring-tutorials/
0
 
LVL 7

Author Comment

by:gudii9
ID: 39891930
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
 
LVL 35

Expert Comment

by:mccarl
ID: 39893377
What was the error message?
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39893815
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
 
LVL 7

Author Comment

by:gudii9
ID: 39893833
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 7

Author Comment

by:gudii9
ID: 39893846
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
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39893847
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
 
LVL 7

Author Comment

by:gudii9
ID: 39893858
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
 
LVL 7

Author Comment

by:gudii9
ID: 39893871
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
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39893879
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
 
LVL 7

Author Comment

by:gudii9
ID: 39893883
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
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39893893
No it shouldn't mess anything up.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now