测试dao报错 :

来源:13-5 dao的迁移下

韩某某大人

2018-05-11

2018-05-11 13:14:14.806 [main] INFO  o.s.b.t.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.tangmo.mlsnl.dao.HomoPageTest], using SpringBootContextLoader

2018-05-11 13:14:14.814 [main] INFO  o.s.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.tangmo.mlsnl.dao.HomoPageTest]: no resource found for suffixes {-context.xml, Context.groovy}.

2018-05-11 13:14:14.815 [main] INFO  o.s.t.c.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.tangmo.mlsnl.dao.HomoPageTest]: HomoPageTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.

2018-05-11 13:14:15.011 [main] INFO  o.s.b.t.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.tangmo.mlsnl.MlsnlServerSideApplication for test class com.tangmo.mlsnl.dao.HomoPageTest

2018-05-11 13:14:15.200 [main] INFO  o.s.b.t.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]

2018-05-11 13:14:15.245 [main] INFO  o.s.b.t.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@757acd7b, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@36b4fe2a, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@574b560f, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@ba54932, org.springframework.test.context.support.DirtiesContextTestExecutionListener@28975c28, org.springframework.test.context.transaction.TransactionalTestExecutionListener@3943a2be, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@343570b7, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@157853da, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@71c3b41, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@236e3f4e, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@3cc1435c, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@6bf0219d]


  .   ____          _            __ _ _

 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \

( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \

 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )

  '  |____| .__|_| |_|_| |_\__, | / / / /

 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::        (v2.0.2.RELEASE)


2018-05-11 13:14:15.863 [main] INFO  com.tangmo.mlsnl.dao.HomoPageTest - Starting HomoPageTest on DESKTOP-388R1K4 with PID 6800 (started by Acer in C:\Users\Acer\Documents\workspace-sts-3.9.4.RELEASE\mlsnl-server-side)

2018-05-11 13:14:15.864 [main] DEBUG com.tangmo.mlsnl.dao.HomoPageTest - Running with Spring Boot v2.0.2.RELEASE, Spring v5.0.6.RELEASE

2018-05-11 13:14:15.869 [main] INFO  com.tangmo.mlsnl.dao.HomoPageTest - No active profile set, falling back to default profiles: default

2018-05-11 13:14:15.937 [main] INFO  o.s.w.context.support.GenericWebApplicationContext - Refreshing org.springframework.web.context.support.GenericWebApplicationContext@6e9a5ed8: startup date [Fri May 11 13:14:15 CST 2018]; root of context hierarchy

2018-05-11 13:14:20.510 [main] WARN  o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - Autowired annotation is not supported on static fields: private static java.lang.String com.tangmo.mlsnl.config.dao.SessionFactoryConfiguration.entityPackage

2018-05-11 13:14:20.550 [main] INFO  com.mchange.v2.log.MLog - MLog clients using java 1.4+ standard logging.

2018-05-11 13:14:20.729 [main] INFO  com.mchange.v2.c3p0.C3P0Registry - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]

2018-05-11 13:14:21.795 [main] INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

2018-05-11 13:14:22.365 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.web.context.support.GenericWebApplicationContext@6e9a5ed8: startup date [Fri May 11 13:14:15 CST 2018]; root of context hierarchy

2018-05-11 13:14:22.508 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)

2018-05-11 13:14:22.512 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)

2018-05-11 13:14:22.571 [main] INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

2018-05-11 13:14:22.571 [main] INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

2018-05-11 13:14:24.145 [main] INFO  com.tangmo.mlsnl.dao.HomoPageTest - Started HomoPageTest in 8.805 seconds (JVM running for 10.357)

2018-05-11 13:14:25.271 [main] INFO  c.m.v2.c3p0.impl.AbstractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 2, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 10000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge0y79vljc6ck1v79ng7|77b325b3, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge0y79vljc6ck1v79ng7|77b325b3, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://127.0.0.1:3306/mlsnl?useUnicode=true&characterEncoding=utf8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]

2018-05-11 13:14:26.491 [main] DEBUG com.tangmo.mlsnl.dao.HomePageDao.queryUser - ==>  Preparing: SELECT * FROM `user` 

2018-05-11 13:14:26.544 [main] DEBUG com.tangmo.mlsnl.dao.HomePageDao.queryUser - ==> Parameters: 

2018-05-11 13:14:26.586 [main] DEBUG com.tangmo.mlsnl.dao.HomePageDao.queryUser - <==      Total: 5

2018-05-11 13:14:26.614 [Thread-2] INFO  o.s.w.context.support.GenericWebApplicationContext - Closing org.springframework.web.context.support.GenericWebApplicationContext@6e9a5ed8: startup date [Fri May 11 13:14:15 CST 2018]; root of context hierarchy


写回答

2回答

韩某某大人

提问者

2018-05-11

老师,这个问题已经解决了,能不能问您一个问题,之前我看过您的构建简单的小程序项目。 我想问小程序要调用别的商家的优惠券要怎么做。

1
5
翔仔
回复
韩某某大人
感谢同学的支持:)同学有什么问题都可以留言,最近加班比较忙,有空的话肯定知无不言:)
2018-05-12
共5条回复

翔仔

2018-05-11

同学好,请问能否描述一下是什么错误,并且错误信息是啥。。这一大长串的信息没看出错在哪里了呀,主要看你junit那栏报了什么。同时你也可以对比我的config配置看看。并建议你用springboot1.5.8版本,和视频保持一致

DataSourceConfiguration.java

package com.imooc.o2o.config.dao;

import java.beans.PropertyVetoException;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.imooc.o2o.util.DESUtil;
import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * 配置datasource到ioc容器里面
 * 
 * @author xiangze
 *
 */
@Configuration
// 配置mybatis mapper的扫描路径
@MapperScan("com.imooc.o2o.dao")
public class DataSourceConfiguration {
	@Value("${jdbc.driver}")
	private String jdbcDriver;
	@Value("${jdbc.url}")
	private String jdbcUrl;
	@Value("${jdbc.username}")
	private String jdbcUsername;
	@Value("${jdbc.password}")
	private String jdbcPassword;

	/**
	 * 生成与spring-dao.xml对应的bean dataSource
	 * 
	 * @return
	 * @throws PropertyVetoException
	 */
	@Bean(name = "dataSource")
	public ComboPooledDataSource createDataSource() throws PropertyVetoException {
		// 生成datasource实例
		ComboPooledDataSource dataSource = new ComboPooledDataSource();
		// 跟配置文件一样设置以下信息
		// 驱动
		dataSource.setDriverClass(jdbcDriver);
		// 数据库连接URL
		dataSource.setJdbcUrl(jdbcUrl);
		// 设置用户名
		dataSource.setUser(DESUtil.getDecryptString(jdbcUsername));
		// 设置用户密码
		dataSource.setPassword(DESUtil.getDecryptString(jdbcPassword));
		// 配置c3p0连接池的私有属性
		// 连接池最大线程数
		dataSource.setMaxPoolSize(30);
		// 连接池最小线程数
		dataSource.setMinPoolSize(10);
		// 关闭连接后不自动commit
		dataSource.setAutoCommitOnClose(false);
		// 连接超时时间
		dataSource.setCheckoutTimeout(10000);
		// 连接失败重试次数
		dataSource.setAcquireRetryAttempts(2);
		return dataSource;
	}

}

SessionFactoryConfiguration.java

package com.imooc.o2o.config.dao;

import java.io.IOException;

import javax.sql.DataSource;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

@Configuration
public class SessionFactoryConfiguration {
	// mybatis-config.xml配置文件的路径
	private static String mybatisConfigFile;

	@Value("${mybatis_config_file}")
	public void setMybatisConfigFile(String mybatisConfigFile) {
		SessionFactoryConfiguration.mybatisConfigFile = mybatisConfigFile;
	}

	// mybatis mapper文件所在路径
	private static String mapperPath;

	@Value("${mapper_path}")
	public void setMapperPath(String mapperPath) {
		SessionFactoryConfiguration.mapperPath = mapperPath;
	}

	// 实体类所在的package
	@Value("${type_alias_package}")
	private String typeAliasPackage;

	@Autowired
	private DataSource dataSource;

	/**
	 * 创建sqlSessionFactoryBean 实例 并且设置configtion 设置mapper 映射路径 设置datasource数据源
	 * 
	 * @return
	 * @throws IOException
	 */
	@Bean(name = "sqlSessionFactory")
	public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
		SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
		// 设置mybatis configuration 扫描路径
		sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(mybatisConfigFile));
		// 添加mapper 扫描路径
		PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
		String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPath;
		sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath));
		// 设置dataSource
		sqlSessionFactoryBean.setDataSource(dataSource);
		// 设置typeAlias 包扫描路径
		sqlSessionFactoryBean.setTypeAliasesPackage(typeAliasPackage);
		return sqlSessionFactoryBean;
	}

}


0
0

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5113 学习 · 8144 问题

查看课程

相似问题