Application.yml-
spring:
profiles: desktop
datasource:
db:
url : jdbc:xxxx
username : xxxx
password : xxxx
driver-class-name: oracle.jdbc.OracleDriver
jndi-name: jndiName
tomcat:
max-wait : 20000
max-active : 5
max-idle : 2
min-idle : 2
Application.java-
@SpringBootApplication
public class Application implements CommandLineRunner {
private static final Logger logger = LogManager.getLogger(Application.class);
@Autowired
private YAMLConfig myConfig;
public static void main(String[] args) {
logger.info("Running application");
SpringApplication.run(Application.class, args);
}
}
DBConfig.java-
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "dbEntityManagerFactory", transactionManagerRef = "dbTransactionManager", basePackages = { "com.et.repo" })
public class DBConfig {
@Primary
@Bean(name = "ldbDataSource")
@ConfigurationProperties(prefix = "spring.datasource.db")
public DataSource dbDataSource() {
return DataSourceBuilder.create().build();
}
@Primary
@Bean(name = "dbEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean dbEntityManagerFactory(EntityManagerFactoryBuilder builder, @Qualifier("dbDataSource") DataSource dataSource) {
return builder.dataSource(dataSource).packages("com.et.entity").persistenceUnit("db").build();
}
@Primary
@Bean(name = "dbTransactionManager")
public PlatformTransactionManager dbTransactionManager(@Qualifier("dbEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
我期望此配置创建名称为“ jndiName”的JNDI,但似乎并未创建它。这段代码什么也没显示-
context = new InitialContext();
log.info("Listing JNDI's");
NamingEnumeration<NameClassPair> list = context.list("");
while (list.hasMore()) {
log.info("Name: " + list.next().getName());
}
我想念什么?我读到某处嵌入式Tomcat默认情况下未启用命名的信息。可以吗?如何通过此配置启用它?