标签:map com repo one artifact sql div apach sep
如果提示无法注入依赖,就考虑没有引用哪个工程,对于war包来说要全部引用,举个栗子:
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>tms</groupId> <artifactId>tms-parent</artifactId> <version>1.0.0</version> </parent> <artifactId>tms-yinliu</artifactId> <name>tms-yinliu</name> <dependencies> <dependency> <artifactId>tms-util</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-api</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> </dependencies> </project>
对于这样的没有war包的分布式,你只需引用你所需要的工程。
对于war包来说要全部引用:
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>tms</groupId> <artifactId>tms-parent</artifactId> <version>1.0.0</version> </parent> <artifactId>tms-yinliu-war</artifactId> <packaging>war</packaging> <name>tms-yinliu-war</name> <dependencies> <dependency> <artifactId>tms-number</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-order</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-user</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-info</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-tk</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-data</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-mobile</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-contract</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-weixin</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-product</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-company</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-yinliu</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> <dependency> <artifactId>tms-business</artifactId> <groupId>tms</groupId> <version>1.0.0</version> </dependency> </dependencies> </project>
<!-- 注解驱动 --> <mvc:annotation-driven/> <!-- 自动扫描的包 --> <context:component-scan base-package="com.pyq.weixin"/>
3. 特别对于mapper层,需要注意一个问题,mybatis中对应的mapper接口无法注入,原因可能是没有扫描到此mapper
<!--错误的 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.pyq.weixin.mapper" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean> <!-- 正确的扫描mapper(dao)包 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.pyq.**.mapper" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean>
由于一个项目中的mapper层不止一个,所以需要扫描到所有的mapper层,需要用到通配符 com.pyq.**.mapper指的是pyq下面所有的mapper层
标签:map com repo one artifact sql div apach sep
原文地址:https://www.cnblogs.com/pangyangqi/p/8875577.html