SpringBoot的Maven父子项目,一直无法将src/main/resource下面的xml文件打包到target/class西面
SpringBoot的Maven父子项目,一直无法将src/main/resource下面的xml文件打包到target/class西面
在Maven父子项目当中的的搭建了一个SpringBpoot的Web模块工程,项目当中的DAO和Service层的接口和实现类都集成公共基类,但是启动报错
项目结构 包名
system
|-system-modle com.system.model
|-system-common com.system.common
|-system-dao com.system.dao
|-system-dao-common com.system.dao.common mybatis文件 resource/main/mybatis/mapper/common/ *.xml
|-system-dao-user com.system.dao.user mybatis文件 resource/main/mybatis/mapper/user/*.xml
|-system-service com.system.service
|-system-service-common com.system.service.common
|-system-service-user com.system.service.user
|-system-web (springboot项目启动类工程) com.system(本项目的启动类SystemWebApplication就放在咋换个包的下面)
|-system-web-common com.system.web.common
|-system-web-user com.system.web.user
项目启动类
@EnableAutoConfiguration
@SpringBootApplication(
exclude = {DataSourceAutoConfiguration.class})
@ComponentScan(basePackages={"com.system.dao",
"com.system.service", "com.system.web.controller"})
@MapperScan(basePackages={"com.system.dao"})
public class SystemWebApplication {
public static void main(String[] args) {
SpringApplication.run(SystemWebApplication.class, args);
}
}
由于此项目的DAO、Service、Web层接口、配置文件和实现类都在其他工程包下面,所以SpringBoot启动类扫描不到这些代码,
所以,我把com.system.dao,com.system.service,com.system.web.controller这几个包都用@ComponentScan配置了出来,
还有DAO层包还有@MapperScan单独配置了出来
application.yml配置文件
server:
port: 8090
spring:
mvc:
view:
prefix: /jsp/
suffix: .jsp
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/system?useUnicode=true&characterEncoding=UTF-8
username: root
password: 123
type: com.alibaba.druid.pool.DruidDataSource
mybatis:
mapper-locations: classpath:mybatis/mapper/*/*.xml
公共DAO接口
public interface IBasicDao<T> {
public int insert(T obj) throws Exception;
public int batchInsert(List<T> list) throws Exception;
public int delete(T obj) throws Exception;
public int deleteById(@Param(value = "id") int id) throws Exception;
public int batchDelete(Integer[] list) throws Exception;
public int update(T obj) throws Exception;
public int batchUpdate(List<T> list) throws Exception;
public T select(@Param(value = "id") int id) throws Exception;
public List<T> selectAll() throws Exception;
public List<T> selectList(T obj) throws Exception;
public T selectNew() throws Exception;
public List<T> selectNewList(@Param(value = "count") int count) throws Exception;
public int getCount(Map<String, Object> param) throws Exception;
public List<T> getSplitList(Map<String, Object> param) throws Exception;
}
用户信息接口
@Mapper
@Component("userBaseDao")
public interface IUserBaseDao extends IBasicDao<UserInfo> {
}
Service层公共接口
public interface IBaseService<T> {
public int add(T obj) throws LogicException;
public int delete(T obj) throws LogicException;
public int deleteById(int id) throws LogicException;
public int update(T obj) throws LogicException;
public T find(int id) throws LogicException;
public List<T> findAll() throws LogicException;
public List<T> findList(T obj) throws LogicException;
}
Service层公共接口实现类
public class BaseServiceImpl<T, I extends IBasicDao<T>> implements IBaseService<T> {
public I getBasicDao() {
return basicDao;
}
public void setBasicDao(I basicDao) {
this.basicDao = basicDao;
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = LogicException.class)
public int add(T obj) throws LogicException {
return basicDao.insert(obj);
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = LogicException.class)
public int delete(T obj) throws LogicException {
return basicDao.delete(obj);
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = LogicException.class)
public int deleteById(int id) throws LogicException {
return basicDao.deleteById(id);
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = LogicException.class)
public int update(T obj) throws LogicException {
return basicDao.update(obj);
}
public T find(int id) throws LogicException {
return basicDao.select(id);
}
public List<T> findAll() throws LogicException {
return basicDao.selectAll();
}
public List<T> findList(T obj) throws LogicException{
return basicDao.selectList(obj);
}
}
用户信息Service层接口
public interface IUserBaseService extends IBaseService<UserBase> {
}
用户信息实现类
@Service("userBaseService")
public class UserBaseServiceImpl extends
BaseServiceImpl<UserBase, IUserBaseDao> implements IUserBaseService {
private Log log = LogFactory.getLog(this.getClass());
@Autowired
@Qualifier("userBaseDao")
private IUserBaseDao userBaseDao;
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public int add(UserBase user) throws LogicException {
return userBaseDao.insert(user);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public int delete(UserBase user) throws LogicException {
return userBaseDao.delete(user);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public int deleteById(int id) throws LogicException {
return userBaseDao.deleteById(id);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public int update(UserBase user) throws LogicException {
return userBaseDao.update(user);
}
@Override
public UserBase find(int id) throws LogicException {
return userBaseDao.select(id);
}
@Override
public List<UserBase > findAll() throws LogicException {
return userBaseDao.selectAll();
}
@Override
public List<UserBase> findList(UserInfo user) throws LogicException {
return userBaseDao.selectList(user);
}
}
项目启动起来,访问后台菜单DAO接口之后报:
2018-06-28 16:26:28.286 ERROR 4884 --- [nio-8090-exec-3] c.j.s.service.menu.impl.MenuServiceImpl : ********** selectListByUser MenuInfo ERROR ********** Exception = org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.
system.dao.menu.IMenuDao.selectListByUserorg.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.system.dao.menu.IMenuDao.selectListByUser
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:223)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
at com.sun.proxy.$Proxy113.selectListByUser(Unknown Source)
at com.system.service.menu.impl.MenuServiceImpl.findListByUser(MenuServiceImpl.java:240)
at com.system.service.menu.impl.MenuServiceImpl$$FastClassBySpringCGLIB$$fd5aa02f.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)
at com.system.service.menu.impl.MenuServiceImpl$$EnhancerBySpringCGLIB$$b68e6a35.findListByUser(<generated>)
at com.system.web.controller.main.MainController.show(MainController.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Applic
我又把 system-dao-user 和 system-dao-common 这个工程下面的 src/main/resource 的项目配置路径也指定到 target/class 这个文件夹下面了
然后,我又按照网上说的Maven的配置
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resource</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
之前搭建的普通的Maven项目,配置了这些,都可以将src/main/resource下面的xml文件打包到target/class西面。
不知道Maven父子工程的SpringBoot项目,有什么特别的,为什么无法将src/main/resource下面的xml文件打包到target/class西面。
请高手帮忙看看,这个问题如何解决???