Java Bean 注册对象
注册对象
POM.xml
<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.3.6</version>
</dependency>
ElasticSearchConfig.java
package com.vipsoft.web.config;
import cn.hutool.core.date.DateUtil;
import com.vipsoft.web.entity.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ElasticSearchConfig {
    @Bean
    public Person client() {
        Person person = new Person();
        person.setName(DateUtil.now());
        return person;
    }
}
EsIndexTest.java
package com.vipsoft.web;
import com.vipsoft.web.entity.Person;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class EsIndexTest {
    Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    Person person;
    @Test
    void connectTest() throws Exception {
        logger.info(person.getName());
    }
}

本文来自博客园,作者:VipSoft 转载请注明原文链接:https://www.cnblogs.com/vipsoft/p/17197100.html
 
                    
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号