标签:iap sch 关于 搭建 pen version oid 接口 domain
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.2.0.RELEASE</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.17</version> </dependency> <dependency> <groupId>commons-dbutils</groupId> <artifactId>commons-dbutils</artifactId> <version>1.7</version> </dependency> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.4</version> </dependency>
package com.sunxiaping.spring5.service; import com.sunxiaping.spring5.domain.Account; public interface IAccountService { void save(Account account); }
package com.sunxiaping.spring5.service.impl; import com.sunxiaping.spring5.dao.IAccountDao; import com.sunxiaping.spring5.domain.Account; import com.sunxiaping.spring5.service.IAccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component("accountService") public class AccountServiceImpl implements IAccountService { @Autowired private IAccountDao accountDao; @Override public void save(Account account) { accountDao.save(account); } }
package com.sunxiaping.spring5.dao; import com.sunxiaping.spring5.domain.Account; /** * 账户的持久层接口 */ public interface IAccountDao { void save(Account account); }
package com.sunxiaping.spring5.dao.impl; import com.sunxiaping.spring5.dao.IAccountDao; import com.sunxiaping.spring5.domain.Account; import org.springframework.stereotype.Component; @Component("accountDao") public class AccountDaoImpl implements IAccountDao { @Override public void save(Account account) { System.out.println("保存账户信息"); } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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"> <!--告知Spring创建容器的时候要扫描的包--> <context:component-scan base-package="com.sunxiaping.spring5"></context:component-scan> </beans>
package com.sunxiaping; import com.sunxiaping.spring5.service.IAccountService; import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class spring5Test { ApplicationContext context = null; @Before public void before() { context = new ClassPathXmlApplicationContext("applicationContext.xml"); } @Test public void test() { IAccountService accountService = context.getBean("accountService", IAccountService.class); accountService.save(null); } }
标签:iap sch 关于 搭建 pen version oid 接口 domain
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/11711342.html