Today, we talk about how to start javaEE novice java EE Spring career.
Of course, development tools will not say, myeclipse + tomcat, you can not tomcat, because myeclipse integrate its own container.
Here to talk about the topic Spring how to start a career,
first: imported spring frame, into which two kinds, one is to download jar package, the other is to add spring frame with myeclipse, of course, we are talking about a second.
Creating web or java project "SpingTest",
right-click on the item found in the "build Path" find "configure Build Path ..."
Then click on the following figure will pop up,
click on the right side of the "Add Library ..." continues to pop up the
selection "MyEclipse Library" Click "Next" to pop up the
find spring xxx Libraries Here I have imported spring 3.1.1 Libraries, so there there will be no spring 3.1.1 package, select the spring you want to import and then "finish" then imported package is complete.
We returned to find that the project will have a project and you just choose a package
Spring framework greet successful we have to simply start our HelloWord it
second: Writing spring HelloWord project
to create a package name "com in the src folder. test.model ", in the name of the package to create a class" HelloWord "
there is only one attribute" message ", and realized the get, set method
now we briefly tested spring framework
spring framework is mainly achieved through logic configuration files
then we to create Spring's core configuration file config.xml.
how fast to create Spring config.xml myeclipse with it?
1. Click Project "SpringTest" find MyEclipse click Myeclipse-project facets-install spring facet , press the icon to find a small patch of green leaves;
3, there will pop open, select the spring version, obtained (according to first import the downloaded files spring spring framework will identify the default version);
4, this step click next, can be configured according to their habits, but try not to file name applicationcontext.xml change
5, here is select the item jar kits, if they have a jar package, knowing jar package to be imported, can here's the check box to remove the check mark that he imported more secure;
6, when the previous step is completed, the configuration found web.xml content have become more content.
A Spring configuration file to quickly create success. Now we are mainly written in the configuration file, we spring configuration file is not named config.xml, you should not worry, I direct the default file system created "applicationContext.xml", in fact, their functions are the same.
I need to write in applicationContext.xml file, I circled part
bean node represents a class, a class a bean, id is the name of their own id, class is your class address, HelloWord we created;
Property is a property representative, we have a class attribute "message" Then we will here only a property,
value represents a property assignment "xxx"
At this point a simple Spring configuration may be considered completed, let's start our test configuration is correct.
Third: Spring test
to create a test class "MainHelloWord", the Main method to achieve
a good, simple to use Spring came to an end. We only need to modify the configuration file is in the Spring when we want to change the message attributes HelloWord class.
Next we will introduce another attribute of Spring injection (DI)
**
Want to learn more programming information, please pay attention to micro-channel public number: IT010101
Want to learn more programming information, please pay attention to micro-channel public number: IT010101
**