习惯了spring注解风格,方便好用,现在用vert.x框架,怎么使用spring注解呢?
2.maven安装依赖包
<!--spring注解依赖包-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
3.注册bean有两个方法:xml注册,注解注册
方法1:xml注册
新建一个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:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 默认单例,,加上scope="prototype"为多例--> <bean name="eatService" class="xue.myVertX.service.serviceImpl.EatServiceImpl" scope="prototype"/> </beans>