我有一个带有一个测试类dbtest的maven模块。运行测试时,不会提取属性文件application.properties。DvsTestDbConfig中的行system.out.println显示的是{database.test},而不是qqqqqqqqq(暂时为虚拟值)。知道为什么spring找不到属性文件吗?
DBTest
package ch.admin.estv.dvs.test.database;
import ch.admin.estv.dvs.test.database.config.DvsTestDbConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@Import(DvsTestDbConfig.class)
public class DbTest {
@Test
public void givenPartnerToDelete_whenPartnerDelete_thenNoEntryExist() {
System.out.println("test started");
}
}
DVSTestDBConfig
package ch.admin.estv.dvs.test.database.config;
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.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.Properties;
@Configuration
@ComponentScan(basePackages = {"ch.admin.estv.dvs.test.database"})
@EnableTransactionManagement
public class DvsTestDbConfig {
@Value("${database.test}")
String databaseTest;
@Autowired
private Environment environment;
@Value("${database.driverClassName}")
String driverClassName;
@Value("${database.url}")
String databaseUrl;
@Value("${database.username}")
String databaseUsername;
@Value("${database.password}")
String databasePassword;
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[]{"ch.admin.estv.dvs.test.database"});
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
return em;
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
System.out.println("************** db property databaseTest : " + databaseTest);
dataSource.setUrl(databaseUrl);
dataSource.setUsername(databaseUsername);
dataSource.setPassword(databasePassword);
dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
Properties additionalProperties() {
Properties properties = new Properties();
//properties.setProperty("hibernate.hbm2ddl.auto", "validate");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
properties.setProperty("hibernate.jdbc.lob.non_contextual_creation", "true");
properties.setProperty("show_sql", "true");
return properties;
}
}
database.test=qqqqqqqqq
database.url=xxxxxxxxxxxxxxxxx
database.username=xxxxxxxxxx
database.password=xxxxxxxxxxx
database.driverClassName=oracle.jdbc.OracleDriver
<parent>
<artifactId>dvs-test</artifactId>
<groupId>ch.admin.estv.dvs</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dvs-test-database</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${ojdbc6.version}</version>
</dependency>
</dependencies>
@PropertySource(value = "classpath:application.properties")
DvsTestDbConfig类上的注释
通过环境解析的属性驻留在一个或多个“属性源”对象中,@Configuration类可以使用@PropertySource注释向环境对象提供属性源:
我一直在尝试运行以下命令 获取以下错误 github。com/x/customValidation/validators。proto:找不到文件。test\u服务器/测试。proto:5:1:Import“github.com/x/customValidation/validators.proto”未找到或有错误。 我可以看到原始文件在这个位置- 我还尝试了使用--proto\u path命令,但
我已经将其隔离到一个非常简单的测试项目中,该项目除了简单的log4j2test配置使用之外没有其他用途。文件目录结构: 建筑sbt: log4j2.xml内容复制/粘贴从示例在官方留档:https://logging.apache.org/log4j/2.x/manual/configuration.html SimpleMain。斯卡拉: 我跑步与 输出:
当我尝试访问我发现一个
我正在处理symfony2,并发现此错误: 未找到名为“Acme”的映射文件。博客包。实体帖子。类“Acme\BlogBundle\Entity\Posts”的php。500内部服务器错误-映射异常 我生成实体php应用程序/控制台原则:生成:实体 实体名称:AcmeBlogBundle:Post 格式:php 我将所有内容放在Acme:BlogBundle:Entity目录中。 这是我使用get
颤振 - 我试图为我的颤振应用程序运行 firebase 身份验证以进行用户身份验证,但我遇到了很多错误。目前,我遇到“致命错误:”GoogleUtilities/GULAppEnvironmentUtil.h“文件未找到#import 你能帮帮我吗?我错过了什么? 下面是我的 podfile.lock
我正在使用优秀的库,希望更新到最新版本,为此我需要使用composer。 文件结构: Composer.json文件: 我试图像这样使用库: 问题是我得到了错误: 致命错误:在第132行的 /home/bookmark/public_html/ajax/action.php中找不到类'mikehaertl\wkhtmlto\Pdf' 这是我第一次使用作曲家,知道我做错了什么吗?