spring注解开发
Posted fjk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring注解开发相关的知识,希望对你有一定的参考价值。
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:c="http://www.springframework.org/schema/c" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 引入注解解析器 --> <context:annotation-config /> <!-- 组件扫描 --> <context:component-scan base-package="com.baidu.test"/> </beans>
UserService
public interface UserService { public abstract void login(); }
UserServiceImp
@Component("UserService") public class UserServiceImp implements UserService{ @Value("zhan") private String name; @Override public void login() { System.out.println("login....."); System.out.println(name); } }
以上是关于spring注解开发的主要内容,如果未能解决你的问题,请参考以下文章