<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    mvn + spring [HelloWorld]

    This quick guide example will use Maven to generate a simple Java project structure, and demonstrates how to retrieve Spring bean and print a “hello world” string.
    Technologies used in this article :
    1. Spring 2.5.6
    2. Maven 2.2.1
    3. Eclipse 3.6
    4. JDK 1.6.0.13

    Generate project structure with maven

    In command prompt, issue following Maven command :
    mvn archetype:create -DgroupId=wei.peng.app -DartifactId=docgenDemo

     

     

    Maven will generated all the Java’s standard folders structure for you (beside resources folder, you need to create it manually)

    Covert 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.

    Add spring dependency
    Add Spring dependency in Maven’s pom.xml file.
    <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/xsd/maven-4.0.0.xsd">
        
    <modelVersion>4.0.0</modelVersion>

        
    <groupId>wei.peng.app</groupId>
        
    <artifactId>docgen-demo</artifactId>
        
    <version>1.0-SNAPSHOT</version>
        
    <packaging>jar</packaging>

        
    <name>docgen-demo</name>
        
    <url>http://maven.apache.org</url>

        
    <properties>
            
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        
    </properties>

        
    <dependencies>
            
    <dependency>
                
    <groupId>junit</groupId>
                
    <artifactId>junit</artifactId>
                
    <version>3.8.1</version>
                
    <scope>test</scope>
            
    </dependency>
            
    <!-- 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.

    Spring Bean
    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.
    package wei.peng.app;

    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;

    /**
     * 
    @author Administrator
     * Hello world! (Maven + Spring)
     
    */
    public class HelloWorld {

        
    private String name;
        
        
    public void setName(String name) {
            
    this.name = name;
        }

        
    public void printHello() {
            System.out.println(
    "Hello " + name);
        }
        
        
    public static void main(String[] args){
            ApplicationContext context 
    = new ClassPathXmlApplicationContext("docgen-transformations-beans.xml");
            HelloWorld obj 
    = (HelloWorld) context.getBean("helloBean");
            obj.printHello();
        }
    }

    Spring bean configuration file
    Create a xml file (Spring-Module.xml) at “src/main/resources/docgen-transformations-beans.xml“. This is the Spring’s bean configuration files, which declared all the available Spring beans.
    <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="wei.peng.app.HelloWorld">
            
    <property name="name" value="Wpeng" />
        
    </bean>
     
    </beans>

    Run it

     

    posted on 2012-11-05 20:22 鹽城小土包 閱讀(226) 評論(0)  編輯  收藏 所屬分類: J2EE

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿

    隨筆檔案(14)

    文章分類(18)

    文章檔案(18)

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产传媒在线观看视频免费观看| 亚洲乱色伦图片区小说| 亚洲av无码成人精品区| 色播精品免费小视频| 人人狠狠综合久久亚洲高清| 一级看片免费视频囗交| 亚洲av无码专区青青草原| 精品日韩亚洲AV无码一区二区三区 | 久久精品国产这里是免费| 一级毛片完整版免费播放一区| 亚洲色少妇熟女11p| 亚洲午夜成激人情在线影院| 亚洲第一精品福利| 久久亚洲精品视频| 久久久久一级精品亚洲国产成人综合AV区 | 日韩免费高清大片在线| 在线看片免费人成视频播| 三级黄色在线免费观看| 国产精品成人免费观看| 亚洲国产高清视频在线观看| 亚洲AV无码久久| 香蕉高清免费永久在线视频| 在线观看视频免费完整版| 精品一区二区三区高清免费观看 | 亚洲成在人线aⅴ免费毛片| 99re视频精品全部免费| 99视频在线看观免费| 污视频在线观看免费| 性无码免费一区二区三区在线| 免费在线看黄的网站| 一级毛片全部免费播放| 麻豆成人久久精品二区三区免费| 日韩电影免费在线观看中文字幕| 国产免费拔擦拔擦8X高清在线人| 国产综合免费精品久久久| 免费黄网站在线看| 色欲色香天天天综合网站免费| 99ee6热久久免费精品6| 四虎最新永久免费视频| 无码人妻久久一区二区三区免费丨 | 最近中文字幕mv免费高清电影 |