Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autowired issue #30

Open
fsanna13 opened this issue Sep 18, 2021 · 2 comments
Open

Autowired issue #30

fsanna13 opened this issue Sep 18, 2021 · 2 comments

Comments

@fsanna13
Copy link

Using IntelliJ, the Autowired annotation for the jdbcTemplate variable is labeled as an issue.

...
public static void main(String[] args) {
	SpringApplication.run(SpringjdbcApplication.class, args);
}

@Autowired //Field injection is not recommended
JdbcTemplate jdbcTemplate;

@Override
public void run(String... args) throws Exception {
        log.info("Creating tables");
...

It says that "Field injection is not recommended". How to solve this?

@Buzzardo
Copy link
Contributor

Buzzardo commented Oct 9, 2023

I assigned Greg Turnquist to this one, as a way to get a good answer to your question. Once Greg does so, we can close it.

@robertmcnees
Copy link
Contributor

Constructor injection can be used.

//	@Autowired
//	JdbcTemplate jdbcTemplate;

	private final JdbcTemplate jdbcTemplate;

	public RelationalDataAccessApplication(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

I'll leave this open and mark it as good for a first time contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants