@@ -5,9 +5,7 @@ | |||||
<artifactId>parent</artifactId> | <artifactId>parent</artifactId> | ||||
<version>0.0.1-SNAPSHOT</version> | <version>0.0.1-SNAPSHOT</version> | ||||
</parent> | </parent> | ||||
<groupId>com.hp</groupId> | |||||
<artifactId>user-parent</artifactId> | <artifactId>user-parent</artifactId> | ||||
<version>0.0.1-SNAPSHOT</version> | |||||
<packaging>pom</packaging> | <packaging>pom</packaging> | ||||
<modules> | <modules> | ||||
<module>user-client</module> | <module>user-client</module> | ||||
@@ -6,7 +6,6 @@ | |||||
<version>0.0.1-SNAPSHOT</version> | <version>0.0.1-SNAPSHOT</version> | ||||
</parent> | </parent> | ||||
<artifactId>user-service</artifactId> | <artifactId>user-service</artifactId> | ||||
<packaging>jar</packaging> | |||||
<dependencies> | <dependencies> | ||||
<!-- 内部依赖--> | <!-- 内部依赖--> | ||||
<dependency> | <dependency> | ||||
@@ -25,6 +24,12 @@ | |||||
<version>0.0.1-SNAPSHOT</version> | <version>0.0.1-SNAPSHOT</version> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>junit</groupId> | |||||
<artifactId>junit</artifactId> | |||||
<version>4.12</version> | |||||
<scope>test</scope> | |||||
</dependency> | |||||
</dependencies> | </dependencies> | ||||
</project> | </project> |
@@ -0,0 +1,16 @@ | |||||
package com.hp.user.service; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
import com.hp.user.service.entity.Account; | |||||
import com.hp.user.service.mapper.TestMapper; | |||||
@Service | |||||
public class TestService { | |||||
@Autowired(required=true) | |||||
TestMapper userMapper; | |||||
public Account Sel(int id){ | |||||
return userMapper.Sel(id); | |||||
} | |||||
} |
@@ -1,8 +1,10 @@ | |||||
package com.hp.user.service; | package com.hp.user.service; | ||||
import org.mybatis.spring.annotation.MapperScan; | |||||
import org.springframework.boot.SpringApplication; | import org.springframework.boot.SpringApplication; | ||||
import org.springframework.boot.autoconfigure.SpringBootApplication; | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | |||||
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; | |||||
/** | /** | ||||
* 用户服务启动类 | * 用户服务启动类 | ||||
@@ -10,13 +12,18 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | |||||
* @since 2020/11/18 | * @since 2020/11/18 | ||||
* | * | ||||
*/ | */ | ||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) | |||||
@MapperScan("com.hp.user.service.mapper") //扫描的mapper | |||||
@SpringBootApplication | |||||
@NacosPropertySource(dataId = "datasource1", autoRefreshed = true) | |||||
public class UserServiceApplaction { | public class UserServiceApplaction { | ||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
SpringApplication.run(UserServiceApplaction.class, args); | SpringApplication.run(UserServiceApplaction.class, args); | ||||
} | } | ||||
} | } |
@@ -0,0 +1,21 @@ | |||||
package com.hp.user.service.controller; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.web.bind.annotation.PathVariable; | |||||
import org.springframework.web.bind.annotation.RequestMapping; | |||||
import org.springframework.web.bind.annotation.RestController; | |||||
import com.hp.user.service.TestService; | |||||
@RestController | |||||
public class TestController { | |||||
@Autowired | |||||
private TestService userService; | |||||
@RequestMapping("getUser/{id}") | |||||
public String GetUser(@PathVariable int id){ | |||||
return userService.Sel(id).getName().toString(); | |||||
} | |||||
} |
@@ -5,18 +5,20 @@ import com.alibaba.nacos.api.config.annotation.NacosValue; | |||||
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; | import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; | ||||
import org.springframework.boot.SpringApplication; | import org.springframework.boot.SpringApplication; | ||||
import org.springframework.boot.autoconfigure.SpringBootApplication; | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | |||||
import org.springframework.context.ConfigurableApplicationContext; | import org.springframework.context.ConfigurableApplicationContext; | ||||
import org.springframework.web.bind.annotation.GetMapping; | import org.springframework.web.bind.annotation.GetMapping; | ||||
import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
@SpringBootApplication | |||||
@NacosPropertySource(dataId = "springboot2-nacos-config", autoRefreshed = true) | @NacosPropertySource(dataId = "springboot2-nacos-config", autoRefreshed = true) | ||||
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) | |||||
@RestController | @RestController | ||||
public class Test{ | |||||
public class Test1{ | |||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
try { | try { | ||||
ConfigurableApplicationContext context = SpringApplication.run(Test.class, args); | |||||
ConfigurableApplicationContext context = SpringApplication.run(Test1.class, args); | |||||
System.out.print(context.getEnvironment().getProperty("nacos.test.propertie")); | System.out.print(context.getEnvironment().getProperty("nacos.test.propertie")); | ||||
}catch(Exception e) { | }catch(Exception e) { |