《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
org.springframework
spring-jdbc
${spring.version}
org.springframework
spring-aspects
${spring.version}
jstl
jstl
${jstl.version}
javax.servlet
servlet-api
${servlet-api.version}
provided
javax.servlet
jsp-api
${jsp-api.version}
provided
com.alibaba
dubbo
${dubbo-version}
com.101tec
zkclient
${zkClient-version}
src/main/java
**/*.xml
src/main/resources
**/*.xml
**/*.properties
org.apache.tomcat.maven
tomcat7-maven-plugin
${tomcat.version}
2.1 创建项目
2.2 创建实体类
package com.bobo.pojo;
public class User {
private int id;
private String username;
private int userage;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getUserage() {
return userage;
}
public void setUserage(int userage) {
this.userage = userage;
}
}
3.1 创建项目
3.2 创建UserMapper接口
package com.bobo.mapper;
/**
-
UsersMapper接口文件
-
@author dengp
*/
public interface UsersMapper {
}
3.3 创建 UsersMapper 映射配置文件
<?xml version="1.0" encoding="UTF-8" ?>3.4 4修改 POM 文件
com.bobo
dubbo-pojo
0.0.1-SNAPSHOT
org.mybatis
mybatis
org.mybatis
mybatis-spring
mysql
mysql-connector-java
com.alibaba
druid
src/main/java
**/*.xml
4.1创建dubbo-user-provider
4.1.1 创建项目
4.2创建dubbo-user-interface
4.2.1 创建项目
4.2.2 修改POM文件
com.bobo
dubbo-pojo
0.0.1-SNAPSHOT
4.3创建dubbo-user-service
4.3.1 创建项目
4.3.2 修改POM文件
com.bobo
dubbo-user-interface
0.0.1-SNAPSHOT
com.bobo
dubbo-mapper
0.0.1-SNAPSHOT
com.alibaba
dubbo
com.101tec
zkclient
org.springframework
spring-jdbc
org.springframework
spring-aspects
4.3.3 配置MyBatis与Dubbo
db.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm?characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456
applicationContext-dao.xml
<?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.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location=“classpath:db.properties”/>
classpath:SqlMapperClient.xml
applicationContext-service.xml
<?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.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package=“com.bobo.dubbo.service.impl”/>
applicationContext-trans.xml
<?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.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<tx:advice id=“advice” transaction-manager=“transactionMananger”>
tx:attributes
<tx:method name=“add*” propagation=“REQUIRED”/>
<tx:method name=“modify*” propagation=“REQUIRED”/>
<tx:method name=“update*” propagation=“REQUIRED”/>
<tx:method name=“dorp*” propagation=“REQUIRED”/>
<tx:method name=“del*” propagation=“REQUIRED”/>
<tx:method name=“find*” read-only=“true”/>
</tx:attributes>
</tx:advice>
aop:config
<aop:advisor advice-ref=“advice” pointcut=“execution(* com.bobo.dubbo.service.impl*.*(…))”/>
</aop:config>
SqlMapperClient.xml
<?xml version="1.0" encoding="UTF-8"?>application-dubbo.xml
服务提供者的配置文件我们放到META-INF/spring/目录下,我们通过main方法启动会自动加载该文件。
<?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:aop=“http://www.springframework.org/schema/aop”
xmlns:context=“http://www.springframework.org/schema/context” xmlns:tx=“http://www.springframework.org/schema/tx”
xmlns:dubbo=“http://code.alibabatech.com/schema/dubbo”
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name=“user-provider” />
<dubbo:registry protocol=“zookeeper”
address=“192.168.88.171:2181,192.168.88.172:2181,192.168.88.173:2181”/>
<dubbo:protocol name=“dubbo” port=“20880”/>
4.3.3 测试整合
package com.bobo;
import com.alibaba.dubbo.container.Main;
public class Start {
/**
-
特点:
-
1,自带线程阻塞
-
2,支持优雅关系
-
Main 类下的 main 方法在启动时默认的回去 classpath:/META-INF/spring/*.xml
-
@param args
*/
public static void main(String[] args) {
Main.main(args);
}
}
创建消费者相关的服务。
5.1创建dubbo-user-consumer
5.1.1 创建项目
5.2创建dubbo-user-portal-service
5.2.1 创建项目
5.2.2 修改POM文件
com.bobo
dubbo-user-interface
0.0.1-SNAPSHOT
com.bobo
dubbo-pojo
0.0.1-SNAPSHOT
org.springframework
spring-context
org.springframework
spring-beans
5.3创建dubbo-user-portal
5.3.1 创建项目(war)
5.3.2 修改POM文件
<project xmlns=“http://maven.apache.org/POM/4.0.0” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
4.0.0
com.bobo
dubbo-user-consumer
0.0.1-SNAPSHOT
dubbo-user-portal
war
com.bobo
dubbo-user-portal-service
0.0.1-SNAPSHOT
junit
junit
org.slf4j
slf4j-log4j12
org.springframework
spring-webmvc
jstl
jstl
javax.servlet
servlet-api
provided
javax.servlet
jsp-api
provided
com.alibaba
dubbo
com.101tec
zkclient
org.apache.tomcat.maven
tomcat7-maven-plugin
8082
项目报错手动添加web.xml文件
5.3.3 配置 SpringMVC,Spring,web.xml,Dubbo
applicationContext-dubbo.xml
<?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:aop=“http://www.springframework.org/schema/aop”
xmlns:context=“http://www.springframework.org/schema/context”
xmlns:tx=“http://www.springframework.org/schema/tx”
xmlns:dubbo=“http://code.alibabatech.com/schema/dubbo”
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name=“dubbo-consumer”/>
<dubbo:registry protocol=“zookeeper”
address=“192.168.88.171:2181,192.168.88.172:2181,192.168.88.173:2181” />
applicationContext-service.xml
<?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”
面试题总结
其它面试题(springboot、mybatis、并发、java中高级面试总结等)
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
k.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name=“dubbo-consumer”/>
<dubbo:registry protocol=“zookeeper”
address=“192.168.88.171:2181,192.168.88.172:2181,192.168.88.173:2181” />
applicationContext-service.xml
<?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”
面试题总结
其它面试题(springboot、mybatis、并发、java中高级面试总结等)
[外链图片转存中…(img-lS9EjrSH-1714474304017)]
[外链图片转存中…(img-g30r0L21-1714474304017)]
[外链图片转存中…(img-VojVXK5z-1714474304018)]
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!