<blockquote>
讯享网
讯享网
package com.example.boot3.controller;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;@RestController public class HelloController {讯享网@Autowired private StringRedisTemplate redisTemplate; @GetMapping("/hello") public String Hello(){ return "Hello"; } @GetMapping("/incr") public String incr(){ Long haha = redisTemplate.opsForValue().increment("haha"); return "增加后的为" + haha; }}
讯享网<?xml version=“1.0” encoding=“UTF-8”?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.2.1</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>boot3</artifactId> <version>0.0.1-SNAPSHOT</version> <name>boot3</name> <description>boot3</description> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.2.16</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>
讯享网server: port: 9999 spring: servlet:讯享网multipart: max-file-size: 10MBdata:redis: host: 192.168.92.129 port: 6379 database: 0 password: abc123 lettuce: pool: max-active: 8 max-wait: -1ms max-idle: 8 min-idle: 0 timeout: 5000</pre>
讯享网<?xml version=“1.0” encoding=“UTF-8”?> <beans xmlns=“http://www.springframework.org/schema/beans"讯享网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.xsd"> <bean id="user" class="com.example.boot3.bean.User" scope="prototype"> <property name="id" value="1"></property> <property name="name" value="Jack"></property> </bean> <bean id="cat" class="com.example.boot3.bean.Cat"> <property name="id" value="2"></property> <property name="name" value="Rose"></property> </bean></beans>
讯享网package com.example.boot3;import com.example.boot3.bean.*; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan;@ComponentScan(”com.example“)//改变包扫描路径 @SpringBootApplication(scanBasePackages = ”com.example.boot3“)//手动指定扫描包位置 public class Boot3Application {public static void main(String[] args) { var ioc = SpringApplication.run(Boot3Application.class, args);// for (String name : ioc.getBeanDefinitionNames()) { // System.out.println(name); // } // Object user = ioc.getBean(”user“); // Object user1 = ioc.getBean(”user“); // System.out.println(user == user1); // System.out.println(ioc.getBean(”fastsqlException“));讯享网for (String s : ioc.getBeanNamesForType(Cat.class)) { System.out.println(s); } for (String s : ioc.getBeanNamesForType(Dog.class)) { System.out.println(s); } for (String s : ioc.getBeanNamesForType(User.class)) { System.out.println(s); } Object pig = ioc.getBean("pig"); System.out.println(pig);// for (String s : ioc.getBeanNamesForType(Sheep.class)) { // System.out.println(s); // }Object sheep = ioc.getBean(Sheep.class); System.out.println(sheep); }}
讯享网127.0.0.1:6381> shutdown
not connected> quit
[root@localhost ~]# redis-cli -a abc123 -p 6382 -c –raw
Warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe.
127.0.0.1:6382> shutdown
not connected> quit
[root@localhost ~]# redis-server /myredis/redis6379.conf
[root@localhost ~]# redis-cli -a abc123 -p 6379 –raw
Warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe.
127.0.0.1:6379> get haha
12


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/191841.html