maven父子项目,聚合项目整合SSM

第一步,配置好各个.xml文件
在这里插入图片描述
db.properties来存储数据库等信息,以key-value形式存在

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/remote?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root

sqlMapConfig.xml
主要是配置数据库配置以及mapper映射的

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
		PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
		"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

</configuration>

applicationContext-dao.xml的配置
里边主要是配置数据库连接池,然后整合Mybatis和spring将SqlSessionFactoryBean托管给Sring,还有就是把mapper的包扫描进Spring进行托管。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	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-4.2.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

	<!-- 数据库连接池 -->
	<!-- 加载配置文件 -->
	<context:property-placeholder location="classpath:conf/db.properties" />
	<!-- 数据库连接池 -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
		destroy-method="close">
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="maxActive" value="10" />
		<property name="minIdle" value="5" />
	</bean>
	<!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 数据库连接池 -->
		<property name="dataSource" ref="dataSource" />
		<!-- 加载mybatis的全局配置文件 -->
		<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" />
	</bean>
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="yzx.mapper" />
	</bean>
</beans>

applicationContext-service.xml的配置
在我看来,我们的dao层已经托管给了Spring,现在就需要把Service层扫描进来,然后让Spring托管。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	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-4.2.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

	<!-- 配置包扫描器 -->
	<context:annotation-config/>
	<context:component-scan base-package="yzx">
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
	</context:component-scan>
	
</beans>

springmvc.xml的配置
dao和Service都被Spring扫描进去了,现在把Controller层也扫描进去吧,并在这里配置mvc的三大组件,Servlet,Filter,Listener

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

	<context:component-scan base-package="yzx.controller" />
	<mvc:annotation-driven />
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>
</beans>

此时我们就配置好了SSM。
逆向工程的坑
我们在其他位置用逆向工程生成的Pojo mapper .xml文件时需要对里边的内容进行修改
例如,pojo里的包名,.xml里的命名空间(namespace)等,否则不能用。
此时就大功告成了。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 1. 首先,在Eclipse中创建一个新的Maven项目,选择“Create a simple project”选项。 2. 在“New Maven Project”对话框中,输入项目的GroupId、ArtifactId和Version等信息,然后点击“Finish”按钮。 3. 在Eclipse中导入Maven项目,选择“File”菜单中的“Import”选项,然后选择“Existing Maven Projects”。 4. 在“Import Maven Projects”对话框中,选择父项目的根目录,然后点击“Finish”按钮。 5. 在Eclipse中导入Maven项目,同样选择“File”菜单中的“Import”选项,然后选择“Existing Maven Projects”。 6. 在“Import Maven Projects”对话框中,选择子项目的根目录,然后点击“Finish”按钮。 7. 在Eclipse中配置Maven父子项目的依赖关系,右键单击子项目,选择“Properties”选项,然后选择“Java Build Path”。 8. 在“Java Build Path”对话框中,选择“Projects”选项卡,然后点击“Add”按钮,选择父项目,然后点击“OK”按钮。 9. 在Eclipse中运行Maven父子项目,右键单击父项目,选择“Run As”选项,然后选择“Maven install”。 10. 在Eclipse中查看Maven父子项目的构建结果,右键单击子项目,选择“Refresh”选项,然后查看“target”目录下的构建结果。 ### 回答2: 首先,需要明确maven父子项目的概念。父项目是指包含了一个或多个子项目maven项目,子项目是指一个包含在父项目中的maven项目。父项目主要定义了一些公共的配置,子项目可以继承这些配置。 将maven父子项目导入eclipse需要以下几个步骤: 1. 使用eclipse的maven插件,选择File -> Import... -> Maven -> Existing Maven Projects,选择父项目的pom.xml文件,然后点击Finish。 2. 导入父项目之后,eclipse会自动导入所有的子项目。如果没有自动导入,可以右键父项目,选择Maven -> Update Project,勾选Force Update of Snapshots/Releases选项,点击OK即可。 3. 如果需要在eclipse中对子项目进行修改,需要先将子项目作为一个独立的项目导入。选择File -> Import... -> Maven -> Existing Maven Projects,选择子项目的pom.xml文件,然后点击Finish。注意:在导入子项目时需要选择“Same Workspace”选项,这样子项目才会在同一个workspace下面。 4. 如果需要在eclipse中运行子项目,需要先在父项目中配置子项目的插件。在父项目的pom.xml文件中添加插件配置,然后右键父项目,选择Maven -> Update Project更新配置。然后就可以在eclipse中运行子项目了。 5. 如果需要将父子项目打包为一个jar或war文件,需要在父项目中添加打包配置。在父项目的pom.xml文件中添加打包配置,然后右键父项目,选择Maven -> Update Project更新配置。然后就可以在eclipse中对整个父子项目进行打包。 总之,导入maven父子项目到eclipse需要注意以下几个方面:首先导入父项目,然后eclipse会自动导入所有的子项目;如果需要修改子项目,需要将子项目作为一个独立的项目导入;在父项目中需要对子项目的插件进行配置;如果需要打包整个父子项目,需要在父项目中添加打包配置。 ### 回答3: Maven是一个用于项目建构、依赖管理以及项目信息描述的工具。Eclipse是一个开源的集成开发环境,支持多种编程语言。 在Eclipse中导入Maven父子项目的过程如下: 1. 安装Maven插件 在Eclipse中安装Maven插件是必须的,因为Maven插件提供了与Maven项目的集成。安装Maven插件的方法如下: 1) 打开Eclipse IDE 2) 选择菜单"Help" -> "Eclipse Marketplace" 3) 在弹出的对话框中输入"Maven"并点击"Go"按钮 4) 选择任何一个Maven插件,然后点击"Install"按钮 2. 创建父项目 在Eclipse中创建一个Maven项目需要执行以下几个步骤: 1) 打开Eclipse,点击菜单"File" -> "New" -> "Other…" 2) 选择"Maven"文件夹,然后选择"Maven Project" 3) 在Maven项目向导中选择"Create a simple project"并点击"Next" 4) 在"Project Name"和"Group Id"字段中输入项目的名称和组Id,并在"Packaging"字段中选择"pom" 5) 点击"Finish"按钮来创建Maven项目。 3. 创建子项目 要在Eclipse中创建一个Maven项目,需要使用Maven命令行工具或使用Eclipse中的Maven插件完成。这里我们使用Eclipse中的Maven插件完成。创建Maven项目的步骤如下: 1) 打开Eclipse,右键单击Maven项目 -> "New" -> "Maven Project" 2) 在Maven项目向导中,选择"Create a simple project"并点击"Next" 3) 在"Project Name"字段中输入项目的名称,然后选择父项目的Group Id和Artifact Id 4) 在"Packing"字段中选择项目的打包方式,例如"jar" 5) 点击"Finish"按钮来创建Maven项目。 4. 将子项目添加到父项目中 当所有的子项目都创建完毕后,需要将它们添加到父项目中。要将子项目添加到父项目中,需要完成以下步骤: 1) 打开Maven项目的pom.xml文件 2) 在pom.xml文件中添加子项目的信息。例如: <modules> <module>子项目1</module> <module>子项目2</module> </modules> 3) 保存pom.xml文件。 现在,Maven父子项目已经成功导入到Eclipse中。您可以运行每个子项目或全部子项目,构建和打包这些项目,检查它们之间的依赖关系,并通过Eclipse中的其它工具进行开发。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值