Partage
  • Partager sur Facebook
  • Partager sur Twitter

État HTTP 404 – Non trouvé

    22 novembre 2022 à 10:23:14

    Bonjour, j'ai suivi le tuto

    https://openclassrooms.com/fr/courses/4504771-simplifiez-le-developpement-dapplications-java-avec-spring/4757475-mettre-en-place-lenvironnement-de-developpement

    Cependant, j'ai une erreur État HTTP 404 – Non trouvé

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
             version="4.0">
    
        <display-name>Ticket</display-name>    
    
        <!--listener>
            <listener-class>org.example.demo.ticket.webapp.listener.DependencyInjectionListener</listener-class>
        </listener-->
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <!--context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>org.example.demo.ticket.webapp.bootstrap.SpringConfiguration</param-value>
        </context-param-->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:/bootstrapContext.xml</param-value>
        </context-param>
        <!--context-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </context-param-->
         
        <resource-ref>
            <res-ref-name>jdbc/DB_TICKET</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>
        
        <context-param>  
           <param-name>spring.profiles.active</param-name>  
           <param-value>target_dev</param-value>  
        </context-param>  
        <context-param>  
           <param-name>spring.profiles.default</param-name>  
           <param-value>target_dev</param-value>  
        </context-param>
        <context-param>  
           <param-name>spring.liveBeansView.mbeanDomain</param-name>  
           <param-value>target_dev</param-value>  
        </context-param>  
        
    </web-app>
    
    import javax.ws.rs.ApplicationPath;
    import org.glassfish.jersey.server.ResourceConfig;
    
    @ApplicationPath("/")
    public class RestApplication extends ResourceConfig {
    
        //
        // Constructeur par défaut.
        //
        public RestApplication() {
            packages("org.example.demo.ticket.webapp.rest");
        }
    }
    @Path("/projets")
    @Produces(MediaType.APPLICATION_JSON)
    public class ProjetResource extends AbstractResource {
    	
    	//private ManagerFactory managerFactory = ManagerFactory.getInstance();	
    
        /**
         * Renvoie le {@link Projet} d'identifiant {@code pId}
         *
         * @param pId identifiant du {@link Projet}
         * @return Le {@link Projet}
         * @throws NotFoundException Si le {@link Projet} n'a pas été trouvé
         */
        @GET
        @Path("{id}")
        public Projet get(@PathParam("id") Integer pId) throws NotFoundException {
            Projet vProjet = getManagerFactory().getProjetManager().getProjet(pId);
            return vProjet;
        }
    
    
        /**
         * Renvoie tous les {@link Projet}
         *
         * @return List
         */
        @GET
        public List<Projet> get() {
        	System.out.println("Liste des projets");
            ProjetManager vProjetManager = new ProjetManagerImpl();
            List<Projet> vListProjet = vProjetManager.getListProjet();
            return vListProjet;
        }
    }
    
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns="http://www.springframework.org/schema/beans"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
                                http://www.springframework.org/schema/beans/spring-beans.xsd"
          >
    
        <!-- Inclusion d'autres fichiers de contexte Spring -->
        <import resource="classpath:/org/example/demo/ticket/consumer/consumerContext.xml"/>
        <import resource="classpath:/org/example/demo/ticket/business/businessContext.xml"/>
        <import resource="classpath:/org/example/demo/ticket/webapp/webappContext.xml" />
    </beans>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns="http://www.springframework.org/schema/beans"
        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">
    
        <!-- Prend en compte la configuration des injections (@Inject...) -->
        <context:annotation-config/>
    
        <!-- Scanne les packages pour trouver les beans qui se déclarent (@Named...) -->
        <context:component-scan base-package="org.example.demo.ticket"/>
    
        <!-- ==== AbstractResource ===== -->
        <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
            <property name="targetClass" value="org.example.demo.ticket.webapp.rest.resource.AbstractResource"/>
            <property name="targetMethod" value="setManagerFactory"/>
            <property name="arguments" ref="managerFactory"/>
        </bean>
    </beans>


    http://localhost:8080/ticket-webapp/

    la page accueil s'affiche correctement

    http://localhost:8080/ticket-webapp/projets

    État HTTP 404 – Non trouvé


    Type Rapport d'état

    message La ressource demandée [/ticket-webapp/projets] n'est pas disponible

    description La ressource demandée n'est pas disponible.

    nov. 22, 2022 8:44:52 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Nom version serveur :              Apache Tomcat/9.0.68
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Serveur compilé :                  Oct 3 2022 19:06:10 UTC
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Version du serveur :               9.0.68.0
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Nom de l'OS :                      Windows 10
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Version OS :                       10.0
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Architecture :                     amd64
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Java Home :                        C:\Java\jdk-14
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Version JVM :                      14+36-1461
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Fournisseur de la JVM :            Oracle Corporation
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: CATALINA_BASE :                    C:\Projets\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: CATALINA_HOME :                    C:\Server\Tomcat\V9.0.68
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Argument de la ligne de commande : -Dcatalina.base=C:\Projets\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Argument de la ligne de commande : -Dcatalina.home=C:\Server\Tomcat\V9.0.68
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Argument de la ligne de commande : -Dwtp.deploy=C:\Projets\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
    nov. 22, 2022 8:44:53 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Argument de la ligne de commande : -Dfile.encoding=Cp1252
    nov. 22, 2022 8:44:53 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
    INFO: La librairie Apache Tomcat Native basée sur APR qui permet des performances optimales dans les environnements de production n'a pas été trouvée sur le java.library.path : [C:\Java\jdk-14\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Java/jdk-14/bin/server;C:/Java/jdk-14/bin;C:\Python39\Scripts\;C:\Python39\;C:\Python38\Scripts\;C:\Python38\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Microsoft VS Code\bin;C:\Java\jdk-14\bin;C:\apache-maven-3.6.3\bin;C:\Program Files\Git\cmd;C:\curl-7.70.0-win64-mingw\bin;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\apache-ant-1.9.15\bin;C:\Program Files\nodejs\;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\Laplace\AppData\Local\Microsoft\WindowsApps;C:\Users\Laplace\AppData\Local\atom\bin;C:\Users\Laplace\AppData\Roaming\npm;C:\Users\Laplace\AppData\Local\Microsoft\WindowsApps;C:\Users\Laplace\.dotnet\tools;C:\Eclipse202003R;;.]
    nov. 22, 2022 8:44:55 AM org.apache.coyote.AbstractProtocol init
    INFO: Initialisation du gestionnaire de protocole ["http-nio-8080"]
    nov. 22, 2022 8:44:55 AM org.apache.catalina.startup.Catalina load
    INFO: L'initialisation du serveur a pris [5186] millisecondes
    nov. 22, 2022 8:44:56 AM org.apache.catalina.core.StandardService startInternal
    INFO: Démarrage du service [Catalina]
    nov. 22, 2022 8:44:56 AM org.apache.catalina.core.StandardEngine startInternal
    INFO: Démarrage du moteur de Servlets : [Apache Tomcat/9.0.68]
    nov. 22, 2022 8:44:57 AM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
    WARNING: La création de l'instance de SecureRandom pour le générateur d'id de session en utilisant [SHA1PRNG] a pris [292] millisecondes
    nov. 22, 2022 8:45:11 AM org.apache.jasper.servlet.TldScanner scanJars
    INFO: Au moins un fichier JAR a été analysé pour trouver des TLDs mais il n'en contenait pas, le mode "debug" du journal peut être activé pour obtenir une liste complète de JAR scannés sans succès ; éviter d'analyser des JARs inutilement peut améliorer sensiblement le temps de démarrage et le temps de compilation des JSPs
    nov. 22, 2022 8:45:11 AM org.apache.catalina.core.ApplicationContext log
    INFO: No Spring WebApplicationInitializer types detected on classpath
    nov. 22, 2022 8:45:11 AM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring root WebApplicationContext
    INFO  [main] org.springframework.web.context.ContextLoader : Root WebApplicationContext: initialization started
    DEBUG [main] org.springframework.web.context.support.XmlWebApplicationContext : Refreshing Root WebApplicationContext
    DEBUG [main] org.springframework.beans.factory.xml.XmlBeanDefinitionReader : Loaded 3 bean definitions from class path resource [org/example/demo/ticket/consumer/consumerContext.xml]
    DEBUG [main] org.springframework.beans.factory.xml.XmlBeanDefinitionReader : Loaded 5 bean definitions from class path resource [org/example/demo/ticket/business/businessContext.xml]
    DEBUG [main] org.springframework.beans.factory.xml.XmlBeanDefinitionReader : Loaded 1 bean definitions from class path resource [org/example/demo/ticket/webapp/webappContext.xml]
    DEBUG [main] org.springframework.beans.factory.xml.XmlBeanDefinitionReader : Loaded 9 bean definitions from class path resource [bootstrapContext.xml]
    DEBUG [main] org.springframework.ui.context.support.UiApplicationContextUtils : Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@4e6f3d08]
    DEBUG [main] org.springframework.beans.factory.support.DefaultListableBeanFactory : Creating shared instance of singleton bean 'projetDao'
    DEBUG [main] org.springframework.beans.factory.support.DefaultListableBeanFactory : Creating shared instance of singleton bean 'ticketDao'
    DEBUG [main] org.springframework.beans.factory.support.DefaultListableBeanFactory : Creating shared instance of singleton bean 'daoFactory'
    DEBUG [main] org.springframework.beans.factory.support.DefaultListableBeanFactory : Creating shared instance of singleton bean 'projetManager'
    DEBUG [main] org.springframework.beans.factory.support.DefaultListableBeanFactory : Creating shared instance of singleton bean 'ticketManager'
    DEBUG [main] org.springframework.beans.factory.support.DefaultListableBeanFactory : Creating shared instance of singleton bean 'managerFactory'
    DEBUG [main] org.springframework.beans.factory.support.DefaultListableBeanFactory : Creating shared instance of singleton bean 'txManagerTicket'
    DEBUG [main] org.springframework.beans.factory.support.DefaultListableBeanFactory : Creating shared instance of singleton bean 'dataSourceTicket'
    DEBUG [main] org.springframework.jndi.JndiTemplate : Looking up JNDI object with name [java:comp/env/jdbc/DB_TICKET]
    DEBUG [main] org.springframework.jndi.JndiObjectFactoryBean : Located object with JNDI name [java:comp/env/jdbc/DB_TICKET]
    DEBUG [main] org.springframework.core.env.PropertySourcesPropertyResolver : Found key 'spring.liveBeansView.mbeanDomain' in PropertySource 'servletContextInitParams' with value of type String
    INFO  [main] org.springframework.web.context.ContextLoader : Root WebApplicationContext initialized in 3901 ms
    nov. 22, 2022 8:45:17 AM org.apache.coyote.AbstractProtocol start
    INFO: Démarrage du gestionnaire de protocole ["http-nio-8080"]
    nov. 22, 2022 8:45:18 AM org.apache.catalina.startup.Catalina start
    INFO: Le démarrage du serveur a pris [22310] millisecondes





    • Partager sur Facebook
    • Partager sur Twitter
      24 novembre 2022 à 8:58:03

      j'ai changé la version de javax-servlet à 3.1.0 et jersey 2.27 et

      quand je teste http://localhost:8080/ticket-webapp/tickets/search?projetId=2

      j'ai l'erreur

      INFO  [http-nio-8080-exec-7] org.example.demo.ticket.webapp.rest.resource.ticket.TicketResource : [TicketResource] [search] projetId 2
      INFO  [http-nio-8080-exec-7] org.example.demo.ticket.business.impl.TicketManagerImpl : [TicketManagerImpl] [getListTicket] RechercheTicket Id 2
      INFO  [http-nio-8080-exec-7] org.example.demo.ticket.business.impl.TicketManagerImpl : [TicketManagerImpl] [getTicketDao] 
      INFO  [http-nio-8080-exec-7] org.example.demo.ticket.business.impl.TicketManagerImpl : [TicketManagerImpl] [getTicketDao] ticketDao is null 
      nov. 24, 2022 7:43:57 AM org.apache.catalina.core.StandardWrapperValve invoke
      SEVERE: Servlet.service() du Servlet [org.example.demo.ticket.webapp.config.ServerConfig] dans le contexte au chemin [/ticket-webapp] a retourné une exception [java.lang.NullPointerException] avec la cause
      java.lang.NullPointerException
      	at org.example.demo.ticket.business.impl.TicketManagerImpl.getListTicket(TicketManagerImpl.java:100)
      	at org.example.demo.ticket.webapp.rest.resource.ticket.TicketResource.search(TicketResource.java:63)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      	at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76)
      	at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:148)
      	at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191)
      	at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:243)
      	at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103)
      	at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493)
      	at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415)
      	at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104)
      	at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:277)
      	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
      	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
      	at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
      	at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
      	at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
      	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
      	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
      	at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
      	at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
      	at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
      	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
      	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
      	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
      	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
      	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
      	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
      	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
      	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
      	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
      	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
      	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
      	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
      	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
      	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
      	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
      	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1789)
      	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
      	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
      	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      	at java.base/java.lang.Thread.run(Thread.java:832)
      
      
      public class TicketManagerImpl extends AbstractManagerImpl implements TicketManager {
      @Inject
          @Named("txManagerTicket")
          private PlatformTransactionManager platformTransactionManager;
          
          @Inject
          private TicketDao ticketDao;
      
      	private TransactionHelper transactionHelper;
      
      @Override  
          public List<Ticket> getListTicket(RechercheTicket pRechercheTicket) {
          	//System.out.println("[TicketManagerImpl] [getListTicket] RechercheTicket Id " + pRechercheTicket.getProjetId());
          	logger.info("[TicketManagerImpl] [getListTicket] RechercheTicket Id " + pRechercheTicket.getProjetId());
          	
          	List<Ticket> vList = getTicketDao().findAll(pRechercheTicket);
      
      public TicketDao getTicketDao() {
          	logger.info("[TicketManagerImpl] [getTicketDao] ");    
          	if (ticketDao==null)
          		logger.info("[TicketManagerImpl] [getTicketDao] ticketDao is null ");
      		return ticketDao;
      	}
      }
      public abstract class AbstractManagerImpl {
      	
      	private static final Log logger = LogFactory.getLog(AbstractManagerImpl.class);
      	
      	@Inject
          @Named("daoFactory")
          private DaoFactory daoFactory;
      
      	public DaoFactory getDaoFactory() {
      		logger.info("[AbstractManager]");
      		if(daoFactory == null) {
      			logger.info("[AbstractManager] daoFactory is null");
      			daoFactory = new org.example.demo.ticket.business.impl.DaoFactory().getInstance();
      		}			
      		return daoFactory;
      	}
      
      	public void setDaoFactory(DaoFactory daoFactory) {
      		this.daoFactory = daoFactory;
      	}
      }
      
      
      package org.example.demo.ticket.business.impl;
      
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.SQLException;
      
      import javax.inject.Inject;
      import javax.inject.Named;
      
      import org.example.demo.ticket.consumer.contract.dao.ProjetDao;
      import org.example.demo.ticket.consumer.contract.dao.TicketDao;
      import org.springframework.beans.factory.annotation.Value;
      import org.springframework.context.annotation.PropertySource;
      import org.springframework.context.annotation.PropertySources;
      import org.springframework.context.support.ClassPathXmlApplicationContext;
      
      //@Named("daoFactory")
      //@PropertySources({ @PropertySource("classpath:src/data/conf/db-ticket.properties") })
      @PropertySources({ @PropertySource("classpath:/org/example/demo/ticket/batch/db-ticket.properties") })
      public class DaoFactory {
      	//@Value("${spring.datasource.url}")
      	
      	//@Configuration
      	//@PropertySource("classpath:db.properties")
      	//@PropertySource("classpath:root.properties")
      	//System.out.println("Getting DBConnection Bean for App: "+env.getProperty("APP_NAME"));
      	//root.properties    
      	//APP_NAME=PropertySource Example
      	//db-ticket.properties
      	
      	@Value( "${url}" )
          private static String url;
      	@Value( "${username}" )
          private static String username;
      	@Value( "${password}" )
          private static String password;
      	@Value( "${driverClassName}" )
          private static String driver;
          
          //@Inject
          //private ProjetDao projetDao;
          //@Inject
          //private TicketDao ticketDao;
      
          DaoFactory() {
              this.url = "jdbc:mysql://localhost:3306/ticket?useSSL=false&createDatabaseIfNotExist=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
              this.username = "user";
              this.password = "pass";
          }
      
          DaoFactory(String url, String username, String password) {
              this.url = url;
              this.username = username;
              this.password = password;
          }
      
          public DaoFactory getInstance() {
              try {
                  //Class.forName(driver); 
                  Class.forName("com.mysql.cj.jdbc.Driverr"); 
                  //Class.forName("com.mysql.jdbc.Driver");
              } catch (ClassNotFoundException e) {
      
              }
              
              DaoFactory instance = new DaoFactory(
                      "jdbc:mysql://localhost:3306/ticket?useSSL=false&createDatabaseIfNotExist=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", "laplace", "123456");
              
              
              //DaoFactory instance = new DaoFactory();
              //instance.setUrl(url);
              //instance.setUsername(username);
              //instance.setPassword(password); 
              
              //instance.setUrl("jdbc:mysql://localhost:3306/ticket?useSSL=false&createDatabaseIfNotExist=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC");
              
              return instance;
          }
      	
      	/*public Connection getConnection() {
      		String url = "jdbc:mysql:localhost:3306/db_ticket";
      		String user = "user";
      		String password = "pass";
      		Connection c = null;
      		try {
      			Class.forName("com.mysql.cj.jdbc.Driver");
      		    c = DriverManager.getConnection(url,user,password);
      		} catch (ClassNotFoundException | SQLException cndfe) {
      		}
      	    return c;
          }*/
      
          public static Connection getConnection() throws SQLException {
              Connection connexion = DriverManager.getConnection(url, username, password);        
              connexion.setAutoCommit(false);
              return connexion; 
          }
      
      	/*public ProjetDao getProjetDao() {
      		return projetDao;
      	}
      
      	public void setProjetDao(ProjetDao projetDao) {
      		this.projetDao = projetDao;
      	}
      
      	public TicketDao getTicketDao() {
      		return ticketDao;
      	}
      
      	public void setTicketDao(TicketDao ticketDao) {
      		this.ticketDao = ticketDao;
      	}*/
      
      	public String getUrl() {
      		return url;
      	}
      
      	public void setUrl(String url) {
      		this.url = url;
      	}
      
      	public String getUsername() {
      		return username;
      	}
      
      	public void setUsername(String username) {
      		this.username = username;
      	}
      
      	public String getPassword() {
      		return password;
      	}
      
      	public void setPassword(String password) {
      		this.password = password;
      	}
          
      	
          
      
          // Récupération du Dao
          //public UtilisateurDao getUtilisateurDao() {
          //    return new UtilisateurDaoImpl(this);
          //}
      }





      • Partager sur Facebook
      • Partager sur Twitter

      État HTTP 404 – Non trouvé

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      • Editeur
      • Markdown