title: How to connect to jdbc using @Bean in Spring MVC?
body: <p>I am using Spring MVC. I am trying to connect to jdbc with DriverManagerDataSource. I am using
  @Bean annotation. I am basically trying to achieve something like this in the xml file using annotations.</p>
  <pre><code>&lt;bean id=&quot;dataSource&quot;
      class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&gt;
      &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot; /&gt;
      &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:3306/jcg&quot; /&gt;
      &lt;property name=&quot;username&quot; value=&quot;root&quot; /&gt;
      &lt;property name=&quot;password&quot; value=&quot;toor&quot; /&gt;
  &lt;/bean&gt;
  </code></pre>
  <p>I am using @configuration annotation in my configuration class, doing this to connect using @Bean in my configuration file.</p>
  <pre><code>@Bean
  public DriverManagerDataSource dataSource(){
      Properties jdbcProperties = PropertyUtils.getProperties(profile, &quot;jdbc&quot;);
      
      DriverManagerDataSource ret = new DriverManagerDataSource();
      ret.setDriverClassName(jdbcProperties.getProperty(&quot;driverClassName&quot;));
      ret.setUsername(jdbcProperties.getProperty(&quot;username&quot;));
      ret.setPassword(jdbcProperties.getProperty(&quot;password&quot;));
      ret.setUrl(jdbcProperties.getProperty(&quot;url&quot;));
      return ret;
  }
  </code></pre>
  <p>I saw this in another stackoverflow question. Is this the correct way?
  But I am getting the error.</p>
  <blockquote>
  <p>Properties cannot be resolved</p>
  <p>PropertyUtils cannot be resolved</p>
  </blockquote>
  <p>I am not sure how I can import these? Also I dont understand what profile stands for here? Can you please help?</p>