本人是一名即将进入大三的物联网工程专业的学生,写博客即是为了记录自己的学习历程,又希望能够帮助到很多和自己一样处于起步阶段的萌新。
临渊羡鱼,不如退而结网。一起加油!
博客主页:https://blog.csdn.net/qq_44895397
创建一个接口:
public interface StudentService {
String getName(String name);
}
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>com.yky.springboot</groupId>
<artifactId>springbootdemossminterface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
#tomcat的配置
server.port=8090
server.servlet.context-path=/
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springboot?serverTimezone=UTC&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=yky
spring.redis.host=localhost
spring.redis.port=6379
#spring.redis.password=yky #密码
mybatis.mapper-locations=classpath:mapper/*.xml
#服务名称
spring.application.name=springbootdemossmprivoder
#设置当前工程为服务提供者
spring.dubbo.server=true
#设置注册中心
spring.dubbo.registry=zookeeper://localhost:2181
@Component
@Service(interfaceName = "com.yky.springboot.service.StudentService",
version = "1.0-SNAPSHOT",timeout = 15000)
public class StudentServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;
@Override
public Student queryStudentById(Integer id) {
return studentMapper.selectByPrimaryKey(id);
}
}
@MapperScan(basePackages = “com.yky.springboot.mapper”):扫描mapper文件
@EnableDubboConfiguration:加开启 Dubbo 配置
@SpringBootApplication
@MapperScan(basePackages = "com.yky.springboot.mapper")
@EnableDubboConfiguration
public class SpringbootdemossmprivoderApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootdemossmprivoderApplication.class, args);
}
}
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*
src/main/resources
**/ *.*</include>
</includes>
</resource>
</resources>
<!--dubbo,jsp-->
<!--Dubbo 集成 SpringBoot 框架起步依赖-->
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<!--Zookeeper 客户端依赖-->
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
<!--spring boot内嵌的jsp依赖,解析jsp页面-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!--接口工程-->
<dependency>
<groupId>com.yky.springboot</groupId>
<artifactId>springbootdemossminterface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
#tomcat
server.port=8080
server.servlet.context-path=/
#视图解析器
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
#dubbo服务消费者的配置
#设置dubbo的配置
spring.application.name=springbootdemossmconsumer
#设置注册中心
spring.dubbo.registry=zookeeper://localhost:2181
@Controller
public class StudentController {
@Reference(interfaceName = "com.yky.springboot.service.StudentService",
version = "1.0-SNAPSHOT", check = false)
private StudentService service;
@RequestMapping("/student/{stuid}")
public ModelAndView selectStudent(@PathVariable("stuid") Integer id) {
ModelAndView mv = new ModelAndView();
Student student = service.queryStudentById(id);
mv.addObject("student", student);
mv.setViewName("studentjsp");
return mv;
}
}
@EnableDubboConfiguration
ConfigurableApplicationContext
,它也是一个ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("");
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
//关闭启动 logo 的输出
springApplication.setBannerMode(Banner.Mode.OFF);
springApplication.run(args);
} }
在 src/main/resources 放入 banner.txt 文件
可以利用网站生成图标: https://www.bootschool.net/ascii