Summary of problems encountered in establishing MAVEN modular project __java

Source: Internet
Author: User

First, development tools: Idea
Second, the database: MySQL
Third, language: Java
Iv. Record of issues:

    1, write test classes to test, you need to pay attention to the dependency to rely on another module, the scope of test can not inherit, such as:

Pom.xml under the Xxx-commons module:

<!--unit Test-->
        <dependency>
            <groupId>junit</groupId>
            <artifactid>junit </artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>

When Xxx-manager relies on xxx-commons, the top two jars cannot be relied upon:

        <dependency>
            <groupId>com.ssl</groupId>
            <artifactid>xxx-commons</artifactid >
            <version>1.0-SNAPSHOT</version>
        </dependency>

At this point, JUnit and spring-test are not introduced to the Xxx-manager module, but when Xxx-manager is a xxx-commons child module, it can be referenced.

2, the use of spring-test, JUnit writing test classes, you need to introduce

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactid>javax.servlet-api </artifactId>
            <scope>provided</scope>
        </dependency>

3, pay attention to the difference between classpath* and classpath: classpath* will scan each module classpath, and classpath only scan the current module.

4, when using MyBatis, when the SQL XML file and Mapper file is not in the same directory, configure the sqlsessionfactory, you need to use the specified mapperlocations, for example:

<!--  configuration sqlsessionfactory-->
    <bean id= "sqlsessionfactory" class= " Org.mybatis.spring.SqlSessionFactoryBean ">
             <!--mybatis configuration file, loaded paging plugin-->
            <property name=" Configlocation "value=" Classpath:mybatis/sqlmapconfi.xml "/> <property name=" DataSource "ref=" DataSource
            "/>
            <!--specify Mapping.xml file-->
            <property name=" mapperlocations "value=" classpath:com/ssl/shop/ Mapper/xml/*.xml "/>
    </bean>
    <!--Configure scan packages to load Mapper proxy objects-->
    <bean class=" Org.mybatis.spring.mapper.MapperScannerConfigurer ">
        <property name=" Basepackage "value=" Com.ssl.shop.mapper "/>
    </bean>

5, Idea, by clicking on the right of MAVEN projects, there will be various MAVEN project dependencies and plug-in details, can also select Plug-ins, directly run, but plugins under the Install-install:install command will be an error, You should select the square m icon above (Execute maven Goal), select the module's directory, and then fill in the Install command, and then click Execute.

6, the execution of install, will also run the test class method, if the test class in the failure of the method, it will cause the module install failure, need to pay attention.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.