Я пытаюсь внедрить источник данных в мой контроллер и использую этот (источник данных) объект подключения.Я использую весеннюю загрузку. Я написал два класса конфигурации: один для подключения к Oracle и другой для подключения к Teradata
Для oracle все работает нормально, но для создания источника данных teradata я не смог найти хороший пример, поэтому воткак выглядит моя конфигурация:
@Component
@Configuration
@ConfigurationProperties("application")
public class TeradataConfiguration {
@NotNull
private String usernameTeradata;
@NotNull
private String passwordTeradata;
@NotNull
private String servernameTeradata;
@NotNull
private String charsetTeradata;
@NotNull
private String tmodeTeradata;
@NotNull
private String dsnameTeradata;
@NotNull
private String portTeradata;
@NotNull
private String timeoutTeradata;
public void setUsernameTeradata(String usernameTeradata) {
this.usernameTeradata = usernameTeradata;
}
public void setPasswordTeradata(String passwordTeradata) {
this.passwordTeradata = passwordTeradata;
}
public void setServernameTeradata(String servernameTeradata) {
this.servernameTeradata = servernameTeradata;
}
public void setCharsetTeradata(String charsetTeradata) {
this.charsetTeradata = charsetTeradata;
}
public void setTmodeTeradata(String tmodeTeradata) {
this.tmodeTeradata = tmodeTeradata;
}
public void setDsnameTeradata(String dsnameTeradata) {
this.dsnameTeradata = dsnameTeradata;
}
public void setPortTeradata(String portTeradata) {
this.portTeradata = portTeradata;
}
public void setTimeoutTeradata(String timeoutTeradata) {
this.timeoutTeradata = timeoutTeradata;
}
@Bean
DataSource teraDataSource() throws SQLException {
TeraDataSource teraDataSource = new TeraDataSource();
teraDataSource.setServerName(dsnameTeradata);
teraDataSource.setuser(usernameTeradata);
teraDataSource.setpassword(passwordTeradata);
teraDataSource.setCharSet(charsetTeradata);
teraDataSource.setTMODE(tmodeTeradata);
teraDataSource.setDSName(dsnameTeradata);
teraDataSource.setDbsPort(portTeradata);
teraDataSource.setLoginTimeout(Integer.valueOf(timeoutTeradata));
return teraDataSource;
}
}
После этого я ввел этот bean-компонент в свой контроллер, но когда я делаю:
teraDataSource.getConnection();
Я получаюниже исключения:
TERAJDBC4 ERROR [http-nio-8080-exec-1]
com.teradata.jdbc.jdk6.JDK6_SQL_Connection@fc561d Connection to TEST_DB Fri Oct 05 16:03:10 IST 2018 socket orig=TEST_DB cid=28fb20be sess=0 java.net.UnknownHostException: TEST_DB at
java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at
java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) at
java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getAllByName0(InetAddress.java:1276) at
java.net.InetAddress.getAllByName(InetAddress.java:1192) at
java.net.InetAddress.getAllByName(InetAddress.java:1126) at
com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF$Lookup.doLookup(TDNetworkIOIF.ja
va:223) at
com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF$Lookup.getAddresses(TDNetworkIOI
F.java:261) at
com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF.connectToHost(TDNetworkIOIF.java
:381) at
com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF.createSocketConnection(TDNetwork
IOIF.java:156) at com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF.<init>
(TDNetworkIOIF.java:142) at
com.teradata.jdbc.jdbc.GenericTeradataConnection.getIO(GenericTeradataConn
ection.java:143) at
com.teradata.jdbc.jdbc.GenericLogonController.run(GenericLogonController.j
ava:100) at com.teradata.jdbc.jdbc_4.TDSession.<init>
(TDSession.java:211) at com.teradata.jdbc.jdk6.JDK6_SQL_Connection.
<init>(JDK6_SQL_Connection.java:36) at
com.teradata.jdbc.jdk6.JDK6ConnectionFactory.constructSQLConnection(JDK6Co
nnectionFactory.java:25) at
com.teradata.jdbc.jdbc.ConnectionFactory.createConnection(ConnectionFactor
y.java:181) at
com.teradata.jdbc.jdbc.ConnectionFactory.createConnection(ConnectionFactor
y.java:171) at
com.teradata.jdbc.TeraDataSourceBase.createNewConnection(TeraDataSourceBas
e.java:696) at
com.teradata.jdbc.TeraDataSource.getConnection(TeraDataSource.java:21)
at
com.test.dnb.dao.CompanyProfileDAO.writeToTeradataTable(CompanyProfileDAO.
java:1052) at
com.test.dnb.application.Controller.companyFamilyFullTree(Controller.java:
641) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
62) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorIm
pl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(Inv
ocableHandlerMethod.java:205) at
org.springframework.web.method.support.InvocableHandlerMethod.invokeForReq
uest(InvocableHandlerMethod.java:133) at
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHand
lerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) at
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandle
rAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandle
rAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.ha
ndle(AbstractHandlerMethodAdapter.java:85) at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherSer
vlet.java:967) at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServ
let.java:901) at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkS
ervlet.java:970) at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.ja
va:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.
java:846) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicati
onFilterChain.java:231) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilter
Chain.java:166) at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicati
onFilterChain.java:193) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilter
Chain.java:166) at
org.springframework.web.filter.RequestContextFilter.doFilterInternal(Reque
stContextFilter.java:99) at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerReques
tFilter.java:107) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicati
onFilterChain.java:193) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilter
Chain.java:166) at
org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(H
ttpPutFormContentFilter.java:108) at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerReques
tFilter.java:107) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicati
onFilterChain.java:193) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilter
Chain.java:166) at
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(Hid
denHttpMethodFilter.java:81) at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerReques
tFilter.java:107) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicati
onFilterChain.java:193) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilter
Chain.java:166) at
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(Ch
aracterEncodingFilter.java:197) at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerReques
tFilter.java:107) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicati
onFilterChain.java:193) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilter
Chain.java:166) at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.
java:199) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.
java:96) at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBa
se.java:504) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:1
40) at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:8
1) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.ja
va:87) at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342
) at
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.ja
va:66) at
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProto
col.java:790) at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.j
ava:1459) at
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.jav
a:49) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:
1149) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java
:624) at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.
java:61) at java.lang.Thread.run(Thread.java:748)
Ниже приведены свойства, которые я использую:
> application.servernameTeradata=server.com
> application.usernameTeradata=user
> application.passwordTeradata=pass
> application.charsetTeradata=UTF8
> application.tmodeTeradata=ANSI
> application.dsnameTeradata=TEST_DB
> application.portTeradata=1025
> application.timeoutTeradata=180000
Я могу подключиться к teradata через обычный jdbc, используя Class.forName («Имя драйвера»)но возникли проблемы с источником данных.
Заранее спасибо