本文整理汇总了Java中org.springframework.stereotype.Service类的典型用法代码示例。如果您正苦于以下问题:Java Service类的具体用法?Java Service怎么用?Java Service使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Service类属于org.springframework.stereotype包,在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBeanName
import org.springframework.stereotype.Service; //导入依赖的package包/类
private String getBeanName(Class<?> clazz) {
Component component = clazz.getAnnotation(Component.class);
if (component != null)
return component.value();
Repository repository = clazz.getAnnotation(Repository.class);
if (repository != null)
return repository.value();
Service service = clazz.getAnnotation(Service.class);
if (service != null)
return service.value();
Controller controller = clazz.getAnnotation(Controller.class);
if (controller != null)
return controller.value();
return null;
}
示例2: route
import org.springframework.stereotype.Service; //导入依赖的package包/类
public ThirdPayService route(PayChannel channel, PayType payType) throws Exception {
if (thirdClassList == null)
throw new Exception(ErrorMsgConstant.CHANNEL_NOT_SUPPORT);
for (Class<?> clz : thirdClassList) {
ChannelValue comment = clz.getAnnotation(ChannelValue.class);
if (comment == null)
continue;
if (comment.channel() != channel)
continue;
if (!ArrayUtils.contains(comment.payType(), payType))
continue;
Service service = clz.getAnnotation(Service.class);
if (service == null)
continue;
return (ThirdPayService) SpringContextHelper.getBean(service.value());
}
throw new Exception(ErrorMsgConstant.CHANNEL_NOT_SUPPORT);
}
示例3: route
import org.springframework.stereotype.Service; //导入依赖的package包/类
public ThirdBankVerifyService route(BankRequest request) throws Exception {
if (request == null || request.getInfo().getChannel() == null) {
throw new Exception("当前暂不支持的第三方支付渠道");
}
if (thirdClassList == null)
throw new Exception("当前暂不支持的第三方支付渠道");
for (Class<?> clz : thirdClassList) {
ChannelValue comment = clz.getAnnotation(ChannelValue.class);
if (comment == null)
continue;
if (comment.channel() != request.getInfo().getChannel())
continue;
Service service = clz.getAnnotation(Service.class);
if (service == null)
continue;
return (ThirdBankVerifyService) SpringContextHelper.getBean(service.value());
}
throw new Exception("当前暂不支持的第三方支付渠道");
}
示例4: parseCacheDuration
import org.springframework.stereotype.Service; //导入依赖的package包/类
private void parseCacheDuration(ApplicationContext applicationContext) {
final Map<String, Long> cacheExpires = new HashMap<>();
String[] beanNames = applicationContext.getBeanNamesForType(Object.class);
for (String beanName : beanNames) {
final Class clazz = applicationContext.getType(beanName);
Service service = findAnnotation(clazz, Service.class);
if (null == service) {
continue;
}
addCacheExpires(clazz, cacheExpires);
}
logger.debug("初始化redisCacheManager, 配置有过期时间的key, 内容如下:" + cacheExpires);
//设置有效期
super.setExpires(cacheExpires);
}
示例5: init
import org.springframework.stereotype.Service; //导入依赖的package包/类
@PostConstruct
public void init() {
List<Class<?>> classList = ClassUtil.getClasses(ArcticleService.class.getPackage().getName());
for (Class<?> aClass : classList) {
if (aClass.isAnnotationPresent(Service.class)) {
for (Method method : aClass.getDeclaredMethods()) {
if (method.isAnnotationPresent(ValidateGroup.class)) {
String key = method.toString();
LOGGER.info("init validators of method {}", key);
validateConcurrentMap.put(key, getFiledValidators(key, method));
}
}
}
}
}
示例6: findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes
import org.springframework.stereotype.Service; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() throws Exception {
Class<?> startClass = MetaConfigWithDefaultAttributesTestCase.class;
Class<ContextConfiguration> annotationType = ContextConfiguration.class;
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class,
ContextConfiguration.class, Order.class, Transactional.class);
assertNotNull(descriptor);
assertEquals(startClass, descriptor.getRootDeclaringClass());
assertEquals(annotationType, descriptor.getAnnotationType());
assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
assertArrayEquals(new Class[] { MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.class },
descriptor.getAnnotationAttributes().getClassArray("classes"));
assertNotNull(descriptor.getComposedAnnotation());
assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType());
}
示例7: findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes
import org.springframework.stereotype.Service; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() throws Exception {
Class<?> startClass = MetaConfigWithOverriddenAttributesTestCase.class;
Class<ContextConfiguration> annotationType = ContextConfiguration.class;
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class,
ContextConfiguration.class, Order.class, Transactional.class);
assertNotNull(descriptor);
assertEquals(startClass, descriptor.getRootDeclaringClass());
assertEquals(annotationType, descriptor.getAnnotationType());
assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
assertArrayEquals(new Class[] { MetaAnnotationUtilsTests.class },
descriptor.getAnnotationAttributes().getClassArray("classes"));
assertNotNull(descriptor.getComposedAnnotation());
assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType());
}
示例8: resetAndReconfigure
import org.springframework.stereotype.Service; //导入依赖的package包/类
public void resetAndReconfigure(boolean debug) {
SingularContextSetup.reset();
ApplicationContextMock applicationContext = new ApplicationContextMock();
ServiceRegistryLocator.setup(new SpringServiceRegistry());
new ApplicationContextProvider().setApplicationContext(applicationContext);
registerBeanFactories(applicationContext);
registerAnnotated(applicationContext, Named.class);
registerAnnotated(applicationContext, Service.class);
registerAnnotated(applicationContext, Component.class);
registerAnnotated(applicationContext, Repository.class);
registerMockitoTestClassMocksAndSpies(applicationContext);
getLogger().info("Contexto configurado com os beans: ");
if (debug) {
applicationContext.listAllBeans().forEach(
b -> getLogger().info(b)
);
}
}
示例9: getHandlers
import org.springframework.stereotype.Service; //导入依赖的package包/类
@Override
public List<MaraAnnotationHandler> getHandlers() throws ToolException {
List<MaraAnnotationHandler> handlers = new ArrayList<>();
Reflections reflections = initReflections(getBasePackagesToScanForComponents());
Set<Class<?>> handlerClasses = reflections.getTypesAnnotatedWith(Service.class);
for (Class<?> handlerClass : handlerClasses) {
if (MaraAnnotationHandler.class.isAssignableFrom(handlerClass)) {
try {
MaraAnnotationHandler handler = (MaraAnnotationHandler) handlerClass.newInstance();
handlers.add(handler);
} catch (InstantiationException | IllegalAccessException e) {
throw new ToolException(e);
}
}
}
return handlers;
}
示例10: setup
import org.springframework.stereotype.Service; //导入依赖的package包/类
@Before
public void setup() throws ToolException {
annotationUtil = MaraAnnotationUtil.INSTANCE;
// Initialize our annotations handlers
Configuration conf = new Configuration();
this.job = mock(Job.class);
when(job.getConfiguration()).thenReturn(conf);
AnnotatedTool tool = mock(AnnotatedTool.class);
AnnotatedToolContext context = mock(AnnotatedToolContext.class);
when(tool.getContext()).thenReturn(context);
try {
Reflections reflections = new Reflections("com.conversantmedia.mapreduce.tool.annotation");
Set<Class<?>> handlerClasses = reflections.getTypesAnnotatedWith(Service.class);
for (Class<?> handlerClass : handlerClasses) {
if (MaraAnnotationHandler.class.isAssignableFrom(handlerClass)) {
MaraAnnotationHandler handler = (MaraAnnotationHandler) handlerClass.newInstance();
annotationUtil.registerAnnotationHandler(handler, tool);
}
}
} catch (InstantiationException | IllegalAccessException e) {
throw new ToolException(e);
}
}
示例11: getBeanName
import org.springframework.stereotype.Service; //导入依赖的package包/类
private String getBeanName(final Class<?> clazz) {
final Component componentAnno = clazz.getAnnotation(Component.class);
if(componentAnno != null && !componentAnno.value().isEmpty()) {
return componentAnno.value();
}
final Service serviceAnno = clazz.getAnnotation(Service.class);
if(serviceAnno != null && !serviceAnno.value().isEmpty()) {
return serviceAnno.value();
}
final Repository repositoryAnno = clazz.getAnnotation(Repository.class);
if(repositoryAnno != null && !repositoryAnno.value().isEmpty()) {
return repositoryAnno.value();
}
final Controller controllerAnno = clazz.getAnnotation(Controller.class);
if(controllerAnno != null && !controllerAnno.value().isEmpty()) {
return controllerAnno.value();
}
// ステレオタイプのアノテーションでBean名の指定がない場合は、クラス名の先頭を小文字にした名称とする。
return uncapitalize(clazz.getSimpleName());
}
示例12: getSpringClassAnnotation
import org.springframework.stereotype.Service; //导入依赖的package包/类
private Annotation getSpringClassAnnotation(Class clazz) {
Annotation classAnnotation = AnnotationUtils.findAnnotation(clazz, Component.class);
if (classAnnotation == null) {
classAnnotation = AnnotationUtils.findAnnotation(clazz, Controller.class);
}
if (classAnnotation == null) {
classAnnotation = AnnotationUtils.findAnnotation(clazz, RestController.class);
}
if (classAnnotation == null) {
classAnnotation = AnnotationUtils.findAnnotation(clazz, Service.class);
}
if (classAnnotation == null) {
classAnnotation = AnnotationUtils.findAnnotation(clazz, Repository.class);
}
return classAnnotation;
}
示例13: process
import org.springframework.stereotype.Service; //导入依赖的package包/类
@Nullable
@Override
public <T> AnnotatedComponent<T> process(Scope scope, Class<T> clazz) {
Controller controller = clazz.getAnnotation(Controller.class);
if (controller != null) {
return new AnnotatedComponent(clazz, controller.value(), ComponentType.CONTROLLER);
}
Service service = clazz.getAnnotation(Service.class);
if (service != null) {
return new AnnotatedComponent(clazz, service.value(), ComponentType.CONTROLLER);
}
return null;
}
示例14: DwrClassPathBeanDefinitionScanner
import org.springframework.stereotype.Service; //导入依赖的package包/类
public DwrClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry)
{
super(registry, false);
addExcludeFilter(new AnnotationTypeFilter(Component.class));
addExcludeFilter(new AnnotationTypeFilter(Service.class));
addExcludeFilter(new AnnotationTypeFilter(Repository.class));
addExcludeFilter(new AnnotationTypeFilter(Controller.class));
setScopedProxyMode(ScopedProxyMode.INTERFACES);
}
示例15: testWithComponentAnnotationOnly
import org.springframework.stereotype.Service; //导入依赖的package包/类
@Test
public void testWithComponentAnnotationOnly() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
provider.addExcludeFilter(new AnnotationTypeFilter(Service.class));
provider.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(2, candidates.size());
assertTrue(containsBeanClass(candidates, NamedComponent.class));
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
assertFalse(containsBeanClass(candidates, StubFooDao.class));
assertFalse(containsBeanClass(candidates, NamedStubDao.class));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:ClassPathScanningCandidateComponentProviderTests.java