Summary of problems encountered in building maven modular projects

1. Development tools: idea
2. Database: mysql
3. Language: java
4. Problem record:

    1、编写测试类进行测试的时候,需要注意通过dependency进行依赖另一个模块时候,scope为test的不能继承过来,例如:

pom.xml under the xxx-commons module:

<!-- 单元测试 -->
        <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 depends on xxx-commons, the above two jars cannot be depended on:

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

At this time, junit and spring-test will not be introduced under the xxx-manager module, but when xxx-manager is a submodule of xxx-commons, they can be referenced.

2. When using spring-test and junit to write test classes, you need to introduce

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

3. Note the difference between classpath* and classpath: classpath* will scan the classpath under each module, while classpath only scans the current module.

4. When using mybatis, when the sql xml file and the mapper file are not in the same directory, when configuring the sqlSessionFactory, you need to specify mapperLocations, for example:

<!--  配置sqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
             <!-- mybatis配置文件,加载了分页插件 -->
            <property name="configLocation" value="classpath:mybatis/SqlMapConfi.xml"/>
            <property name="dataSource" ref="dataSource"/>
            <!-- 指定mapping.xml文件 -->
            <property name="mapperLocations" value="classpath:com/ssl/shop/mapper/xml/*.xml"/>
    </bean>
    <!-- 配置扫描包,加载mapper代理对象 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.ssl.shop.mapper"/>
    </bean>

5. In the idea, by clicking the maven projects on the right, there will be dependencies and plugin details of each maven project. You can also select the plugin and run it directly, but the install-install:install command under Plugins will report an error, and the above should be selected at this time. The square M icon (Execute maven Goal), select the directory of the module, then fill in the install command, and finally click Execute.

6. When executing install, it will also run the method in the test class. If the method in the test class fails to run, it will also cause the module install to fail, so you need to pay attention.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325879681&siteId=291194637